Parsing a JSON file

Gents,

I am getting the JSON below from my boiler and zould like to extract the L_statetext value.

{
   "pe1":{
      "L_temp_act":"681",
      "L_temp_set":"700",
      "L_ext_temp":"-32768",
      "L_frt_temp_act":"816",
      "L_frt_temp_set":"80",
      "L_br":"false",
      "L_ak":"false",
      "L_not":"true",
      "L_stb":"true",
      "L_modulation":"0",
      "L_uw_speed":"82",
      "L_state":"99",
      "L_statetext":"Attente",
      "L_type":"1",
      "L_starts":"4972",
      "L_runtime":"2445",
      "L_avg_runtime":"29",
      "L_uw_release":"600",
      "L_uw":"82",
      "L_storage_fill":"0",
      "L_storage_min":"400",
      "L_storage_max":"6000",
      "L_storage_popper":"0",
      "storage_fill_yesterday":"0",
      "mode":"1"
   }
}

I am using the following in a change mode but this doesn't work:

$split(payload.pe1.L_statetext, ',')

The first thing to confirm is whether you have a JSON string, or if it has already been parsed into a JavaScript Object.

If you pass that message to a Debug node, it if shows as a single blob of text, then it is a JSON string. In which case, you will need to pass it through the JSON node to convert it to a JavaScript Object.

Once you have it as an object, then you can use a Change node to set msg.payload to the value of msg.payload.pe1.L_statetext - there is no need to use $split or any other JSONata expression.

Thanks mate,

using the JSON node to convert it to a JavaScript Object was the way to go.

Thank you so much

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