# Best way to parse Json object

**URL:** <https://discourse.nodered.org/t/best-way-to-parse-json-object/34902>\
**Category:** General\
**Created:** [27 October 2020 17:13 UTC](https://discourse.nodered.org/t/best-way-to-parse-json-object/34902 "2020-10-27T17:13:03Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![quito96](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/quito96/32/17252_2.png) [@quito96](https://discourse.nodered.org/u/quito96)\
**Post date:** [27 October 2020 17:13 UTC](https://discourse.nodered.org/t/best-way-to-parse-json-object/34902/1 "2020-10-27T17:13:04Z")

</div>

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.  
Example:  
{"idx":1,"RSSI":6,"nvalue":0,"svalue":"1129;23.0;33024.00“}

i am grateful for every tip.

Thanks Quito

---

<div class="post-metadata">

**Author:** ![kuema](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kuema/32/6542_2.png) [@kuema](https://discourse.nodered.org/u/kuema)\
**Post date:** [27 October 2020 17:28 UTC](https://discourse.nodered.org/t/best-way-to-parse-json-object/34902/2 "2020-10-27T17:28:37Z")

</div>

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"]`

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [27 October 2020 17:31 UTC](https://discourse.nodered.org/t/best-way-to-parse-json-object/34902/3 "2020-10-27T17:31:52Z")

</div>

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  
`Number(values[0])`

---

<div class="post-metadata">

**Author:** ![quito96](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/quito96/32/17252_2.png) [@quito96](https://discourse.nodered.org/u/quito96)\
**Post date:** [27 October 2020 17:39 UTC](https://discourse.nodered.org/t/best-way-to-parse-json-object/34902/4 "2020-10-27T17:39:32Z")

</div>

Hi kuema & colin,

Both examples work. Thank you very 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:** [10 November 2020 17:39 UTC](https://discourse.nodered.org/t/best-way-to-parse-json-object/34902/5 "2020-11-10T17:39:39Z")

</div>

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