HELP extract data from object/json

Sorry but I have need to parse this object

I want extra VolV for each element of array

{"topic":"energy_measurs","payload":{"serial":"A07766","measurs":[{"phaseId":0,"voltV":223,"currentA":2.038,"powerW":364,"powerFactor":0.8009999990463257},{"phaseId":1,"voltV":225.3000030517578,"currentA":2.102,"powerW":412,"powerFactor":0.8690000176429749},{"phaseId":2,"voltV":231.1999969482422,"currentA":0.624,"powerW":80,"powerFactor":0.5569999814033508}],"totPowerW":856,"errorSensor":0}}

Do you really want to create a custom node to do this? If not, could we please ask you to change the category to "general".

1 Like

"An extra VolV" I assume you mean an extra VoltV.
A Change Node with a jsonata expression will do the job.

$$ ~> |payload.measurs|{"VoltV2": voltV}|
You can play with it here. As the test on the JSONata expression editor does not allow

[{"id":"1c99cc328f943a7f","type":"function","z":"66277e057a573726","name":"function 12","func":"msg = {\"topic\":\"energy_measurs\",\"payload\":{\"serial\":\"A07766\",\"measurs\":[{\"phaseId\":0,\"voltV\":223,\"currentA\":2.038,\"powerW\":364,\"powerFactor\":0.8009999990463257},{\"phaseId\":1,\"voltV\":225.3000030517578,\"currentA\":2.102,\"powerW\":412,\"powerFactor\":0.8690000176429749},{\"phaseId\":2,\"voltV\":231.1999969482422,\"currentA\":0.624,\"powerW\":80,\"powerFactor\":0.5569999814033508}],\"totPowerW\":856,\"errorSensor\":0}}\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":370,"y":760,"wires":[["b970d4c17e6a7fc7"]]},{"id":"f3804042146bfa36","type":"inject","z":"66277e057a573726","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":160,"y":760,"wires":[["1c99cc328f943a7f"]]},{"id":"223c3c71312ca5da","type":"debug","z":"66277e057a573726","name":"debug 92","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":760,"y":760,"wires":[]},{"id":"b970d4c17e6a7fc7","type":"change","z":"66277e057a573726","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$$ ~> |payload.measurs|{\"VoltV2\": voltV}|","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":580,"y":760,"wires":[["223c3c71312ca5da"]]}]

Sorry for my English.

I need to extract the tree value of Volts to create 3 sensor from array of json message

Change Node > Set msg.voltV0 = payload.measurs[0].voltV

Same for the rest
payload.measurs[1].voltV
payload.measurs[2].voltV

The "Copy path" button in the debug window is your friend

Thanks perfect!!!!

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.