# Simple question about JSON conversion

**URL:** <https://discourse.nodered.org/t/simple-question-about-json-conversion/28250>\
**Category:** General\
**Created:** [12 June 2020 19:04 UTC](https://discourse.nodered.org/t/simple-question-about-json-conversion/28250 "2020-06-12T19:04:38Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![ikoth](https://avatars.discourse-cdn.com/v4/letter/i/ce73a5/32.png) [@ikoth](https://discourse.nodered.org/u/ikoth)\
**Post date:** [12 June 2020 19:04 UTC](https://discourse.nodered.org/t/simple-question-about-json-conversion/28250/1 "2020-06-12T19:04:38Z")

</div>

Hi there,

I need to convert a true/false boolean return into a JSON object, exchanging the boolean values for "1" or "0":

I've got this far:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/7/17c143ac8e859a318343953f5f4bdcd36effdb64.png)

But I don't know what value to put in the highlighted box, as "msg.payload" doesn't work:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/e/feef10a3aaafcb3d694b5cb710daa408d905932d.png)

Apologies for all the screenshots, but I'm not allowed to upload the flow itself (there is sensitive information in the node obscured by the text label in the flow screenshot.

---

<div class="post-metadata">

**Author:** ![ikoth](https://avatars.discourse-cdn.com/v4/letter/i/ce73a5/32.png) [@ikoth](https://discourse.nodered.org/u/ikoth)\
**Post date:** [12 June 2020 19:06 UTC](https://discourse.nodered.org/t/simple-question-about-json-conversion/28250/2 "2020-06-12T19:06:50Z")

</div>

Sorry, only 2 images allowed for newbies. Here's the flow structure:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/1/311f6356b32264106f16dacb84f341f0930de7c5.png)

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [12 June 2020 19:14 UTC](https://discourse.nodered.org/t/simple-question-about-json-conversion/28250/3 "2020-06-12T19:14:57Z")

</div>

What is your input (json format)?  
What is the expected output (json format)?

---

<div class="post-metadata">

**Author:** ![ikoth](https://avatars.discourse-cdn.com/v4/letter/i/ce73a5/32.png) [@ikoth](https://discourse.nodered.org/u/ikoth)\
**Post date:** [12 June 2020 20:47 UTC](https://discourse.nodered.org/t/simple-question-about-json-conversion/28250/4 "2020-06-12T20:47:05Z")

</div>

The input is boolean true / false. The desired output is as shown in the second screenshot. I just don't know what to put, instead of msg.payload.

Thanks.

---

<div class="post-metadata">

**Author:** ![cinhcet](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cinhcet/32/438_2.png) [@cinhcet](https://discourse.nodered.org/u/cinhcet)\
**Post date:** [12 June 2020 21:29 UTC](https://discourse.nodered.org/t/simple-question-about-json-conversion/28250/5 "2020-06-12T21:29:06Z")

</div>

I honestly don't get it. Do you want your payload to be "1" or "0"? Then just write `"value": "1"` and `"value": "0"` instead of `"value": "msg.payload"`? But I cannot believe that this is what you want...

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [12 June 2020 22:35 UTC](https://discourse.nodered.org/t/simple-question-about-json-conversion/28250/6 "2020-06-12T22:35:45Z")

</div>

Set the change node as:

 ![Screenshot 2020-06-13 at 00.36.43](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/f/7fbc86751ee2fb2a383e692a9153a13909f6ded5.jpeg)

JSONata expression can even be shorter; `**.value = true ? 1 : 0 `

---

<div class="post-metadata">

**Author:** ![ikoth](https://avatars.discourse-cdn.com/v4/letter/i/ce73a5/32.png) [@ikoth](https://discourse.nodered.org/u/ikoth)\
**Post date:** [12 June 2020 22:45 UTC](https://discourse.nodered.org/t/simple-question-about-json-conversion/28250/7 "2020-06-12T22:45:43Z")

</div>

Sorry, I guess this is complicated by the fact that I can't post the flow.

The boolean true/false comes from the "LED state" node to the left of the red line. I'm trying to use the "change" node to the right of the red line to convert those true/false returns into JSON objects, in the format shown, that are then passed to the node hidden by the text box. The JSON "value" key needs to be set to 0 or 1 depending on whether the boolean from "LED State" is either "true" or "false"

---

<div class="post-metadata">

**Author:** ![ikoth](https://avatars.discourse-cdn.com/v4/letter/i/ce73a5/32.png) [@ikoth](https://discourse.nodered.org/u/ikoth)\
**Post date:** [12 June 2020 22:46 UTC](https://discourse.nodered.org/t/simple-question-about-json-conversion/28250/8 "2020-06-12T22:46:53Z")

</div>

Ahhh, that looks promising. I'll give that a try.

Thank you sir!

---

<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:** [11 August 2020 22:47 UTC](https://discourse.nodered.org/t/simple-question-about-json-conversion/28250/9 "2020-08-11T22:47:53Z")

</div>

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