Can I use JSONata to access elements of a msg.payload when it's a buffer of byte?

Google is getting me nowhere :frowning:

Can't you use logic operators?

I don't see any logic operators :frowning:

Have a look here:

That needs JSONata to be extended - which I'm sure is way past my paygrade :slight_smile:

Plus. I'm after access to buffer values e.g. payload.0 payload.1 etc

my actual need is to use JSONata to multiply payload.4 by 256 and then add it to payload.5 to get a 16bit length value

I wonder if the buffer-parser node would let me do this without need for JSONAta?

But I've never managed to understand how to use it :frowning:

To some extent yes

    $data := $$.payload.*;
    $data[4] * 256 + $data[5]
[{"id":"783f92be64ac750f","type":"inject","z":"b779de97.b1b46","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[1,2,3,4,5,6]","payloadType":"bin","x":90,"y":4840,"wires":[["a442df240b88c426"]]},{"id":"a442df240b88c426","type":"change","z":"b779de97.b1b46","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"(\t    $data := $$.payload.*;\t    $data[4] * 256 + $data[5]\t)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":280,"y":4840,"wires":[["7f97c85a28ce873c"]]},{"id":"7f97c85a28ce873c","type":"debug","z":"b779de97.b1b46","name":"debug 347","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":530,"y":4840,"wires":[]}]
1 Like

That worked :slight_smile:
Why do you say to some extent?

Because I was not sure what your actual buffer was, and as others have said if you want to preform bitwise operations I think you you would need to extend JSONata.

ghayne just misunderstood what I was after :slight_smile:

1 Like

You can not blame him, I was unsure until you clarified his responses.


It's not so bad once you "get it". And once you do, you realise why it's laid out as it is and it's power.

You can of course read the explanations in the built in help but this example should give you a head start:

That makes sense :slight_smile:
This seems to do the job for me to produce topicLength

1 Like

Follow up question

Can I make msg.payload be the output rather than a sub property of msg.payload.

Or do I have to use a change node on the output?

I tried leaving Output property empty but that didn't do the job for me

By default, it works in object mode (putting everything in payload). If you chose fan out, each value you ask for will go out of its own pin. If there is only one value to get" there will be only one output. What it outputs on that single pin depends on what you chose for the final "output" drop-down (can't remember options & not at computer - I think there is an entry named "value")

Does the job - thanks very much

1 Like

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