# Parsing a JSON file

**URL:** <https://discourse.nodered.org/t/parsing-a-json-file/51824>\
**Category:** General\
**Created:** [4 October 2021 08:14 UTC](https://discourse.nodered.org/t/parsing-a-json-file/51824 "2021-10-04T08:14:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mathgoy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mathgoy/32/48964_2.png) [@mathgoy](https://discourse.nodered.org/u/mathgoy)\
**Post date:** [4 October 2021 08:14 UTC](https://discourse.nodered.org/t/parsing-a-json-file/51824/1 "2021-10-04T08:14:25Z")

</div>

Gents,

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

```auto
{
   "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:

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

```

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [4 October 2021 08:24 UTC](https://discourse.nodered.org/t/parsing-a-json-file/51824/2 "2021-10-04T08:24:12Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![mathgoy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mathgoy/32/48964_2.png) [@mathgoy](https://discourse.nodered.org/u/mathgoy)\
**Post date:** [4 October 2021 08:29 UTC](https://discourse.nodered.org/t/parsing-a-json-file/51824/3 "2021-10-04T08:29:22Z")

</div>

Thanks mate,

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

Thank you so much

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [18 October 2021 08:29 UTC](https://discourse.nodered.org/t/parsing-a-json-file/51824/4 "2021-10-18T08:29:58Z")

</div>

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