# Json String to object help please

**URL:** https://discourse.nodered.org/t/json-string-to-object-help-please/61344
**Category:** General
**Created:** [15 April 2022 18:07 UTC](https://discourse.nodered.org/t/json-string-to-object-help-please/61344 "2022-04-15T18:07:19Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![MrRodz](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mrrodz/32/60147_2.png) [@MrRodz](https://discourse.nodered.org/u/MrRodz)
#### Post date: [15 April 2022 18:07 UTC](https://discourse.nodered.org/t/json-string-to-object-help-please/61344/1 "2022-04-15T18:07:19Z")

</div>

Hi all, I've got a camera that sends this out on MQTT ,

{ “type”:“MOTION\_A”,  
“trigger”:“ON”, “memo”:“car:80%”, “json”:"[{“api”:“objects”,“found”:{“success”:true,“predictions”:[{“confidence”:0.79541016,“label”:“car”,“y\_min”:629,“x\_min”:1323,“y\_max”:774,“x\_max”:1575}],“duration”:0}}]", “path”:"@4226890"}

I'm struggling to convert it into an object so I can use the info for automations.

ive tried to convert to json but it fails, I've tried a split(",") but I either loose info or I just get errors. trigger, memo, and path are just single entry's but the json section increased with the number of items it finds.

really appreciate some help on this. Thanks

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [15 April 2022 18:14 UTC](https://discourse.nodered.org/t/json-string-to-object-help-please/61344/2 "2022-04-15T18:14:44Z")

</div>

There is a setting in the mqtt out node to output a parse object. check the dropdown in the output section.

---

<div class="post-metadata">

### Author: ![ghayne](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ghayne/32/39_2.png) [@ghayne](https://discourse.nodered.org/u/ghayne)
#### Post date: [15 April 2022 18:21 UTC](https://discourse.nodered.org/t/json-string-to-object-help-please/61344/3 "2022-04-15T18:21:39Z")

</div>

Doesn't look like a valid JSON string!

---

<div class="post-metadata">

### Author: ![MrRodz](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mrrodz/32/60147_2.png) [@MrRodz](https://discourse.nodered.org/u/MrRodz)
#### Post date: [15 April 2022 18:58 UTC](https://discourse.nodered.org/t/json-string-to-object-help-please/61344/4 "2022-04-15T18:58:05Z")

</div>

hi E1cid ,  
thank you I didn't know that was there. it works for the majory of the code except when I add the Json part.

> [@MrRodz](#):
>
> “json”:"[{“api”:“objects”,“found”:{“success”:true,“predictions”:[{“confidence”:0.79541016,“label”:“car”,“y\_min”:629,“x\_min”:1323,“y\_max”:774,“x\_max”:1575}],“duration”:0}}]"

it fail after that.Failed to parse JSON string

regards

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [15 April 2022 19:00 UTC](https://discourse.nodered.org/t/json-string-to-object-help-please/61344/5 "2022-04-15T19:00:34Z")

</div>

You need to escape all the quotes inside the outer two quotes  
eg

```auto
“json”:"[{\“api\”:\“objects\”,\“found\”: ....etc...0}}]"

```

or remove the outer two

```auto
“json”:[{“api”:“objects”,“found”:{“success”:true,“predictions”:[{“confidence”:0.79541016,“label”:“car”,“y_min”:629,“x_min”:1323,“y_max”:774,“x_max”:1575}],“duration”:0}}]

```

---

<div class="post-metadata">

### Author: ![MrRodz](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mrrodz/32/60147_2.png) [@MrRodz](https://discourse.nodered.org/u/MrRodz)
#### Post date: [15 April 2022 19:13 UTC](https://discourse.nodered.org/t/json-string-to-object-help-please/61344/6 "2022-04-15T19:13:40Z")

</div>

I can add variables to the MQTT from the camera but I can't edit the variables data directly. ive renames it to data from json to be a bit more clear. this is how it looks in MQTT explorer. ive taken the other parts out to make it easier to see.

{“data": [{"api":"objects","found":{"success":true,"predictions":[{"confidence":0.67333984,"label":"person","y\_min":1494,"x\_min":1696,"y\_max":1761,"x\_max":1994}],"duration":0}},{"api":"faces","found":{"success":true,"predictions":,"duration":0}}]}

this still says there is a fault with it.

---

<div class="post-metadata">

### Author: ![ghayne](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ghayne/32/39_2.png) [@ghayne](https://discourse.nodered.org/u/ghayne)
#### Post date: [15 April 2022 19:20 UTC](https://discourse.nodered.org/t/json-string-to-object-help-please/61344/7 "2022-04-15T19:20:26Z")

</div>

Can you post the output of the MQTT node connected to a debug node please.

---

<div class="post-metadata">

### Author: ![MrRodz](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mrrodz/32/60147_2.png) [@MrRodz](https://discourse.nodered.org/u/MrRodz)
#### Post date: [15 April 2022 19:23 UTC](https://discourse.nodered.org/t/json-string-to-object-help-please/61344/8 "2022-04-15T19:23:09Z")

</div>

```auto
{“data": [{"api":"objects","found":{"success":true,"predictions":[{"confidence":0.42358398,"label":"dining table","y_min":440,"x_min":1290,"y_max":700,"x_max":1772},{"confidence":0.86376953,"label":"person","y_min":1329,"x_min":1034,"y_max":1770,"x_max":1284}],"duration":0}},{"api":"faces","found":{"success":true,"predictions":[{"confidence":0,"userid":"unknown","y_min":1356,"x_min":1055,"y_max":1423,"x_max":1108}],"duration":0}}]}

```

that's the one part that it fails on. ive removed the other data lines from the camera for clarity

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [15 April 2022 19:29 UTC](https://discourse.nodered.org/t/json-string-to-object-help-please/61344/9 "2022-04-15T19:29:38Z")

</div>

The first quote in “data" is prettified, not the same as the second quote.

---

<div class="post-metadata">

### Author: ![ghayne](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ghayne/32/39_2.png) [@ghayne](https://discourse.nodered.org/u/ghayne)
#### Post date: [15 April 2022 19:31 UTC](https://discourse.nodered.org/t/json-string-to-object-help-please/61344/10 "2022-04-15T19:31:46Z")

</div>

Yep, well spotted. If you change it to a normal quote the string validates!

---

<div class="post-metadata">

### Author: ![MrRodz](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mrrodz/32/60147_2.png) [@MrRodz](https://discourse.nodered.org/u/MrRodz)
#### Post date: [15 April 2022 19:42 UTC](https://discourse.nodered.org/t/json-string-to-object-help-please/61344/11 "2022-04-15T19:42:32Z")

</div>

thank you very much it works. I've put the whole string together and get all the information. Really appreciate you help thank you .

---

<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: [29 April 2022 19:42 UTC](https://discourse.nodered.org/t/json-string-to-object-help-please/61344/12 "2022-04-29T19:42:53Z")

</div>

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