Need help with creating an js object

My case:
I want to create an object which takes the value of x as value of the key location.

the following code does not work :frowning:

context.set('location','UGSK');
let x = context.get('location').valueOf();

msg.payload = JSON.parse('{"location":x,"switch":"Regler NoOp"}');
return msg;

There is no need to use JSON parse - just build the object!

let x = context.get('location').valueOf();
msg.payload = { 
 "location": x,
 "switch": "Regler NoOp"
};
return msg;

PS: not sure why you are calling .valueOf(); ???

ok, the object should look like this:

        node_send(JSON.parse('{"location":"UGSK","switch":"Regler on"}'),context.get('out-regler'));

"UGSK" is the value of the context variable location

        const l = (context.get('location'));
        node_send(l,context.get('out_debug'));
        node_send(JSON.parse('{"location":context.get('location').value.Of,"switch":"Regler NoOp"}'),context.get('out_regler'));

please check the threat. did not reply to you. sorry

problem solved!
I did not need JSON.parse()

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