Best way to parse Json object

Hi there,

i get a json object via MQTT from a CO2 sensor and need a tip how to extract the value of svalue 1129 and 23.0. the value 1129 is 5 or 4 digits.

i am grateful for every tip.

Thanks Quito

A change node with a JSONata split expression might do the trick.

$split(payload.svalue, ';')

That should give you an array containing three values.
["1129", "23.0", "33024.00"]

If, in the MQTT node, you select the output as Parsed JSON then it will parse the JSON string for you and output a javascript object. Then you can reference the properties as, for example, msg.payload.svalue.
Then to parse svalue you can, in a function node, split it at the semi colons into an array using
const values = msg.payload.svalue.split(";")
Now values[0] will be the string "1129", values[1] will be "23.0" and so on.
Finally if you want the values as numbers rather than strings then you can use, for example

Hi kuema & colin,

Both examples work. Thank you very much :slight_smile:

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