Simple question about JSON conversion

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:

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

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.

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

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

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.

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...

Set the change node as:

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

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"

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

Thank you sir!

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