# If json element is false do nothing

**URL:** <https://discourse.nodered.org/t/if-json-element-is-false-do-nothing/89897>\
**Category:** General\
**Created:** [31 July 2024 05:38 UTC](https://discourse.nodered.org/t/if-json-element-is-false-do-nothing/89897 "2024-07-31T05:38:43Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![MichaelRenner](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/michaelrenner/32/78730_2.png) [@MichaelRenner](https://discourse.nodered.org/u/MichaelRenner)\
**Post date:** [31 July 2024 05:38 UTC](https://discourse.nodered.org/t/if-json-element-is-false-do-nothing/89897/1 "2024-07-31T05:38:44Z")

</div>

Moin,

I am using the tankerkoenig node to fetch gas station prices. The result is in json format, the value "prices" goes into an InfluxDB and grafana. Example for the json:

> {  
> "id": "602a47f1-7182-46b6-bcf5-25c7a1d47572",  
> "name": "Access Ludwigshafen-Maudach",  
> "brand": "Access",  
> "street": "Bergstr.",  
> "place": "Ludwigshafen-Maudach",  
> "lat": 49.453446,  
> "lng": 8.375457,  
> "dist": 0,  
> "price": 1.789,  
> "isOpen": true,  
> "houseNumber": "34",  
> "postCode": 67067  
> }

What isn't nice is that even if the gas station is closed, a price is reported and displayed. A price for something that I can't buy (because it's closed) looks wrong to me in the graphic. That's why I'm wondering how I can evaluate the key "isOpen" so that if it's "false", nothing is written to the database?

Any hint?  
Thanks

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [31 July 2024 06:33 UTC](https://discourse.nodered.org/t/if-json-element-is-false-do-nothing/89897/2 "2024-07-31T06:33:09Z")

</div>

Couldn't you do something like:

```auto
let x = (the message you receive with the gas price)
if (x == undefined)
{
    // set the part of the message to be 0
}

```

Then if that part of the message doesn't exist, you get `0`.

Or what ever you wan it to be.

Just a thought.

Ok, after a bit more thought looking at your message:

```auto
let x = msg.price
if (x == undefined)
{
     // What eve you want to do.
}

```

Maybe `return`?

You may need to post the message you get when it is closed.

# Ok, third time lucky:

```auto
let x = msg.isOpen
if (x == false)
{
     msg.price = ""
}
return msg

```

Maybe?

## Or:

```auto
let x = msg.isOpen
if (x == true)
{
    return msg
}
return

```

In the last one if it is false (closed) you could just `return` rather than `return msg`.  
Then nothing would be sent and therefore not add to the database.

Sorry, brain is not playing nicely with me just now.

# \*\* EDITED code for last one to do what you want.

---

<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:** [31 July 2024 06:59 UTC](https://discourse.nodered.org/t/if-json-element-is-false-do-nothing/89897/3 "2024-07-31T06:59:34Z")

</div>

Can you use a switch node, with property payload.isOpen, and rule is true to stop the message moving on?

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [31 July 2024 07:01 UTC](https://discourse.nodered.org/t/if-json-element-is-false-do-nothing/89897/4 "2024-07-31T07:01:51Z")

</div>

Ah, yes. Silly me for not thinking of that too.

Top marks for that idea.

---

<div class="post-metadata">

**Author:** ![MichaelRenner](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/michaelrenner/32/78730_2.png) [@MichaelRenner](https://discourse.nodered.org/u/MichaelRenner)\
**Post date:** [1 August 2024 05:52 UTC](https://discourse.nodered.org/t/if-json-element-is-false-do-nothing/89897/5 "2024-08-01T05:52:00Z")

</div>

Moin E1cid and Trying\_to\_learn,

thanks for all your answers. I choose the switch node with "payload.isOpen" "is true". That work fine. Prices (or dots in the grafana board) only when the gas station is open.  
Thanks so much, Micha

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [1 August 2024 07:39 UTC](https://discourse.nodered.org/t/if-json-element-is-false-do-nothing/89897/6 "2024-08-01T07:39:21Z")

</div>

Yeah, that is the easier way to do it.

---

<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:** [15 August 2024 07:39 UTC](https://discourse.nodered.org/t/if-json-element-is-false-do-nothing/89897/7 "2024-08-15T07:39:26Z")

</div>

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