If json element is false do nothing

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

Couldn't you do something like:

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:

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:

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

Maybe?

Or:

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.

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

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

Top marks for that idea.

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

1 Like

Yeah, that is the easier way to do it.

1 Like

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