Jsonata in combination with the buffer maker of node-red-contrib-buffer-parser

Hi There,

This might be a question for @Steve-Mcl but perhaps someone else has an idea.

I'm using the buffer maker to create a buffer array from a string value, the format is basically: <length of string><string in utf8>, e.g., the string "7.0" becomes [3,55,46,48].

What I'm doing using using JSONata to compute the string length and then create a buffer for the string. But when I use JSONata to obtain the length, i.e., $length($$.version) I get zero, i.e. [3,55,46,48] even though the value is 3:

instead using a number value and the fixed value of 3, I get the required 3 in the buffer array:

The flow using JSONata is attached, replacing the JSONata (in the buffer maker node) with Number field is all I did, i.e, the type and length remains the same. The inject node just defines the version value on the msg object.

Bug? Or Feature? I don't quite understand what's going on .... I can't imagine being the first to be doing this so something is going amiss here :frowning:

Cheers!

[{"id":"54336c7ccef2bba3","type":"buffer-maker","z":"69d58ec6f237a63f","name":"","specification":"spec","specificationType":"ui","items":[{"name":"item1","type":"uint8","length":1,"dataType":"jsonata","data":"$length($$.version)"},{"name":"item2","type":"utf8","length":-1,"dataType":"msg","data":"version"}],"swap1":"","swap2":"","swap3":"","swap1Type":"swap","swap2Type":"swap","swap3Type":"swap","msgProperty":"payload","msgPropertyType":"str","x":342,"y":787,"wires":[["645f2adc666de2e4"]]},{"id":"5e7a894f80e77d0a","type":"inject","z":"69d58ec6f237a63f","name":"","props":[{"p":"version","v":"7.0","vt":"str"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":319,"y":984,"wires":[["54336c7ccef2bba3"]]},{"id":"645f2adc666de2e4","type":"debug","z":"69d58ec6f237a63f","name":"debug 4","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":355,"y":581,"wires":[]}]

Hi @gregorius I don't have time right now to fully digest what you've written. What I will say is if it's the buffer maker then it's quite possibly a bug. That was added much later and doesn't get used anywhere near as much as the buffer Parser.

Just letting you know I'm not ignoring this. Feel free to give me a nudge if I don't get around to answering today or tomorrow.

So it is likely you are either the first to hit this (or the first to report it :wink: ).
I imported your flow and it looks like a bug to me.

I have a feeling this is related to JSONata changes in NR 4 (sync -> async) that I have not had unit tests for. Bah!

If you would be kind enough to raise an issue it will get fixed.

In the meantime, as I am certain you know you can pass the result for the JSONata into the parser as a msg prop.

1 Like

Hi @Steve-Mcl

Yep, that would be the work around - which I will use in due course. Moved on to another problem, will come back to it.

Yep I can do that.

I did have a quick look at the code, but didn't see it so hence I wasn't sure.

EDIT: Pull request is up. The fix is as you said, async v. sync related. It would probably works mostly because normally evaluateProperty doesn't have to do much.