# Converting JSON Object to boolean

**URL:** <https://discourse.nodered.org/t/converting-json-object-to-boolean/39284>\
**Category:** General\
**Created:** [17 January 2021 19:34 UTC](https://discourse.nodered.org/t/converting-json-object-to-boolean/39284 "2021-01-17T19:34:36Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fragmike](https://avatars.discourse-cdn.com/v4/letter/f/f08c70/32.png) [@Fragmike](https://discourse.nodered.org/u/Fragmike)\
**Post date:** [17 January 2021 19:34 UTC](https://discourse.nodered.org/t/converting-json-object-to-boolean/39284/1 "2021-01-17T19:34:37Z")

</div>

Hi..Trying to control my blinds. Really new to this here...tried SEARCH but could not find a solution.

Using a NORA node that delivers a JSON Object  
DEBUG:  
msg.payload : Object

{ openPercent: 0 }

and  
{ openPercent: 100 }

need to control a blind which is toggled with a http in node  
this needs a boolean so I need to convert NORA BLINDS Node from JSON to BOOLEAN

Could not get SWITCH node running because it offers no JSON Source.  
Got now stuck with this

Is there any help?

Regards Michael

---

<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:** [17 January 2021 19:40 UTC](https://discourse.nodered.org/t/converting-json-object-to-boolean/39284/2 "2021-01-17T19:40:40Z")

</div>

You could use a conditional statement in a change node using JSONata or similar in a function node.  
e.g.

```auto
[{"id":"711aea43.2409bc","type":"inject","z":"57675e72.26a0d8","name":"0","props":[{"p":"payload.openPercent","v":"0","vt":"num"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":120,"y":920,"wires":[["fdc0d58.4081c28"]]},{"id":"fdc0d58.4081c28","type":"change","z":"57675e72.26a0d8","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.openPercent > 0 ? true : false","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":350,"y":900,"wires":[["b84dcbfc.816ad"]]},{"id":"e92401aa.c1c7e","type":"inject","z":"57675e72.26a0d8","name":"100","props":[{"p":"payload.openPercent","v":"100","vt":"num"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":140,"y":860,"wires":[["fdc0d58.4081c28"]]},{"id":"b84dcbfc.816ad","type":"debug","z":"57675e72.26a0d8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":580,"y":900,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![Fragmike](https://avatars.discourse-cdn.com/v4/letter/f/f08c70/32.png) [@Fragmike](https://discourse.nodered.org/u/Fragmike)\
**Post date:** [17 January 2021 19:56 UTC](https://discourse.nodered.org/t/converting-json-object-to-boolean/39284/3 "2021-01-17T19:56:13Z")

</div>

Hi. thnx for that fast response, but I don´t know how to interpret your answer. I am not yet used to programming functions. Sorry for that

---

<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:** [17 January 2021 20:04 UTC](https://discourse.nodered.org/t/converting-json-object-to-boolean/39284/4 "2021-01-17T20:04:51Z")

</div>

Import the the flow by pressing ctrl i. Paste the code and click import, then click deploy.

The 2 inject nodes simulate `msg.payload.openPercent` values 1 and 100.  
The change node checks if the `msg,payload.openPercent` is greater than 0. If it is outputs is `true`, if not greater outputs is `false`, and sets that output to `msg.payload`

---

<div class="post-metadata">

**Author:** ![Fragmike](https://avatars.discourse-cdn.com/v4/letter/f/f08c70/32.png) [@Fragmike](https://discourse.nodered.org/u/Fragmike)\
**Post date:** [17 January 2021 20:09 UTC](https://discourse.nodered.org/t/converting-json-object-to-boolean/39284/5 "2021-01-17T20:09:11Z")

</div>

Hi...wow..thnx .will have to try tomorrow. Will report if it worked for me​:+1:💪

---

<div class="post-metadata">

**Author:** ![Fragmike](https://avatars.discourse-cdn.com/v4/letter/f/f08c70/32.png) [@Fragmike](https://discourse.nodered.org/u/Fragmike)\
**Post date:** [18 January 2021 20:53 UTC](https://discourse.nodered.org/t/converting-json-object-to-boolean/39284/6 "2021-01-18T20:53:48Z")

</div>

@E1cid  
Thnx allot. This worked​:muscle:😁👍 Result is exactly what I needed. So the switch node combined with that J "syntax" is the key. Is there any chance for me to learn more about this. I try to read allot and watch youtube tutorials. Any idea where to find a Tut for a dumb noob like me​:thinking:

Got stuck again. Found out, that an output of the json object value will help me to control my blinds and move em in presents he steps. Can you give me a last hint?

Actually I control most of my smarthome with Iobroker, which took me a lot of time to "program" it for my needs. But node red is more powerful, but not that easy for me.  
Thnx allot in advance  
Michael

---

<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:** [18 January 2021 21:19 UTC](https://discourse.nodered.org/t/converting-json-object-to-boolean/39284/7 "2021-01-18T21:19:25Z")

</div>

Hi  
Jsonata [https://jsonata.org/](https://jsonata.org/) is powerful, but you would be better served learning javascript. Jsonata you will pick up on your journey as you start manipulating objects and arrays.

My example was using jsonata, but you could do exactly the same using a function node and javascript, which is often faster and easier to understand.

As to your new issue i have no help as i have no idea what you are doing, when posing a question best to give a good discription of the input and what you expect as output, as you did in your original question. I find if i want to see how something is done, i look here [https://flows.nodered.org/](https://flows.nodered.org/), and search for flows i can pull apart for ideas and examples.

---

<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:** [1 February 2021 21:19 UTC](https://discourse.nodered.org/t/converting-json-object-to-boolean/39284/8 "2021-02-01T21:19:28Z")

</div>

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