Javascript function block help

Would someone have a tip for how to change a msg.payload?

For example the msg.payload going into the function block is Boolean True or False. Can I modify the payload to something different?

var payload = msg.payload

if (payload==True){
    
    // JSON PAYLOAD FOR MOTOR ON
    
    msg.payload = {
    "address": "12345:2",
    "object_type": "analogValue",
    "object_instance": "302",
    "value": "100",
    "priority": "11"
    }
}

if (payload==False){

    // JSON PAYLOAD FOR MOTOR OFF
    
    msg.payload = {
    "address": "12345:2",
    "object_type": "analogValue",
    "object_instance": "302",
    "value": "0",
    "priority": "11"
    }

}

return msg;

Ultimately this needs to be JSON, would I then feed this output into a JSON block? Thanks for any tips

True is pyhton
true is JavaScript
You need javascript

1 Like

Yes if you return an object, No if you return a string in json format.

    // string in JSON format PAYLOAD FOR MOTOR ON
    
    msg.payload = `{
    "address": "12345:2",
    "object_type": "analogValue",
    "object_instance": "302",
    "value": "100",
    "priority": "11"
    }`

Isn't this topic about the same thing as your previous one? You started to ask the question there.

Yes, sorry newbie here. Not sure how ask good questions :roll_eyes:

thats make sense! Thanks for the Python insight I have learned that first now picking up javascript