Syntax Error JsNata

Hi,
i am trying to separate data from a json.
With the change node i always have an syntax error.
What did i wrong ?

Any idea - thx for your help
Olmuk

Using JSONata would be $$.payload.temperature you are missing the . .
Also using msg puts JSONata into compatibility mode, which could be removed at any time.

Saying that you do not require JSONata at all, use the msg type input for both sections of the rule.
set msg. payload
to msg. payload.temperature
should do fine for what you require

1 Like

Canned blurb that will help you not make mistakes...

There’s a great page in the docs (Working with messages : Node-RED) that will explain how to use the debug panel to find the right path/value for any data item.

Pay particular attention to the part about the buttons that appear under your mouse pointer when you over hover a debug message property in the sidebar.

BX00Cy7yHi

And if you find that useful, the next tip is even better...

I recommend watching this playlist: Node-RED Essentials. The videos are done by the developers of node-red. They're nice & short and to the point. You will understand a whole lot more in about 1 hour. A small investment for a lot of gain.

Sorry guys, i can't really transfer your help into my solution.
There is no change with the help from E1cid.

I am not fixed about the Jsonata but i found this into a video.

How would you separate the "temperature" and "humidity" out of the JSON string ?

It isn't a JSON string, it is a javascript object.
What do you mean by separate them? What do you want to do with them?

If you want the temperature in msg.payload, then as suggested earlier use a Change node containing

If your preferred way of learning is from videos you might find Intro to JSON for Node-red useful.

At about 6:15 he shows how you can address a sub property of an object, such as msg.payload.
This "dot" syntax can be used in a function or change node to get the temperature or humidity properties of msg.payload.
Here is a change node

As others have said, Jsonata is unnecessary for this very simple task, but if you really wanted to use it you can do, like this

Many thanks, i guess the json is not in the right way at the ESP32 side - now it is "undefined".
Learning step by step

Use debug nodes to show is what is going into and out of the change node, and how you have configured the change node.

With using the debug nodes i find out with change nod = undefined

With using function nod = ok

I really want to understand how it works and why the change is not working

Instead of posting screen captures, export a simple flow including an inject node with the data and paste it here using the </> button.

That would be because msg.payload is a string, not an Object. Put a JSON node between the input and the change node

Not according to the debug output
image

That, however, is on the assumption that debug 1 is showing the input to the Change node, but we do not know that.

Possibly, but that is the only way that the function can work

const S1=JSON.parse(msg.payload)

If msg.payload was an Object of any kind that would fail, the only way it can not cause an error is if payload is a string.

Plus, there is nothing that tells us where the debug info is actually coming from

You are correct.
@Olmuk I can only repeat my request that you use debug nodes to show is what is going into and coming out of the change node. Until you do that there is little we can do to help you.

Many thanks for your patience and help - the json node do it well
grafik

I am missing the baiscs but i will learn

So where was Debug 1 connected to?