Warning this isn't going to be pretty, I pretty sure non of my terminology will be correct. Don't think it needs saying but I don't really know what I'm doing.
I'm trying to convert a message from JSON to Object/Array? notation. Thought I got close but in the example linked I'm getting and extra "object/array child".
What I need:
0: > "measurement" : "testDevice"
What I'm getting:
0: > "measurement" : > "payload" : "testDevice"
Think my lack of terminaloly if failing me here, as Google might be more help if I new how to search the problem.
Function code:
var msg1 = {payload:msg.payload.device};
var msg2 = {payload:msg.payload.data};
msg.payload = [
{
measurement: msg1,
fields: {
data: msg2
}
}
];
return msg;
Node Example:
[{"id":"f3abc4cf.bf56a8","type":"inject","z":"ec5aafa2.fcafb","name":"JSON String","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"device\":\"testDevice\",\"data\":\"testData\"}","payloadType":"json","x":790,"y":420,"wires":[["d9595840.361e38"]]},{"id":"d9595840.361e38","type":"function","z":"ec5aafa2.fcafb","name":"","func":"var msg1 = {payload:msg.payload.device};\nvar msg2 = {payload:msg.payload.data};\n\nmsg.payload = [\n {\n measurement: msg1,\n fields: {\n data: msg2\n }\n }\n];\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":980,"y":420,"wires":[["23112814.a43278"]]},{"id":"23112814.a43278","type":"debug","z":"ec5aafa2.fcafb","name":"Incorrect","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1160,"y":420,"wires":[]},{"id":"281bada5.7f2602","type":"function","z":"ec5aafa2.fcafb","name":"","func":"msg.payload = [\n {\n measurement: \"testDevice\",\n fields: {\n data: \"testData\",\n },\n }\n];\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":980,"y":380,"wires":[["1289e8ef.e81067"]]},{"id":"4def3a8e.7d8624","type":"inject","z":"ec5aafa2.fcafb","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":780,"y":380,"wires":[["281bada5.7f2602"]]},{"id":"1289e8ef.e81067","type":"debug","z":"ec5aafa2.fcafb","name":"Correct","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1160,"y":380,"wires":[]}]