Referrencing msg.payload in JSON

Show us the complete text you are entering please.

Ok, excuse me, I've solved.
The right syntax was$.topic.
But I had to choose "expression" and not "json" in the to field.
Thank you.

cld

We would still like to see the complete question in context because a lot of people, including me, learn from this forum.

1 Like

Ok, this is the wrong node:
[{"id":"98b6dbec.1356f8","type":"change","z":"d960624e.e361d","name":"create off","rules":[{"t":"set","p":"payload","pt":"msg","to":"{\t \"_id\": $.topic,\t \"screen\": \"off\"\t}","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":260,"y":220,"wires":[[]]}]

this is the good one:
[{"id":"eff8325f.f473f","type":"change","z":"d960624e.e361d","name":"create off","rules":[{"t":"set","p":"payload","pt":"msg","to":"{\t \"_id\": $.topic,\t \"screen\": \"off\"\t}","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":260,"y":100,"wires":[[]]}]

They look the same to me?

Bad:

{
 "_id": $.topic,
 "screen": "off"
}

Good:

{
 "_id": $.topic,
 "screen": "off"
}

@SteveMann the key difference is the type of the field. If you select JSON type, then you cannot do any sort of referencing of message properties - it is entirely static. If you select the Expression type then you can use JSONata expressions that reference message properties.

1 Like

You already know that JSON formatting is my Achilles heel, but after importing the two examples, I see no difference between them. What am I missing?

@SteveMann I agree with you, they are both using an expression and both expressions are identical.

Yup, on inspection the nodes are identical. I'll give @ioclaudio the benefit of the doubt and put that down to copy/paste error given he's acknowledged he needed to use the Expression type rather than JSON.

Yes, my error was to use the wrong type for the field.
I used Json instead of Jsonata.

Wrong:
[{"id":"94f7be69.564c3","type":"change","z":"1802dedb.cf8d01","name":"create off","rules":[{"t":"set","p":"payload","pt":"msg","to":"{\t \"_id\": $.topic,\t \"screen\": \"off\"\t}","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":360,"y":160,"wires":[[]]}]

Right:
[{"id":"94f7be69.564c3","type":"change","z":"1802dedb.cf8d01","name":"create off","rules":[{"t":"set","p":"payload","pt":"msg","to":"{\t \"_id\": $.topic,\t \"screen\": \"off\"\t}","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":360,"y":160,"wires":[[]]}]

cld

I need to pull a global variable using JSON how do I do that
@zenofmud @knolleary

@Zbrooklyn - seeing how this thread is two years old, it would be a good idea if you started a new thread and explained what you are trying to do and what you have done so far.

With that, I'm going to close this thread.