Jsonata $number(hexstring) not working


According to Numeric functions · JSONata the function $number("0x12") should return the parsed number 18 (and not 0x18...)
However in Node-RED 3.0.2 I get error "Unable to cast value to a number"

Can someone confirm ?
I can't seem to find any existing issue on jsonata-js/jsonata however I see that Node-RED use v1.8.6 while the latest release available is 2.0.2
Is it possible to easily update Jsonata on a test instance to see if that solve the problem ?
I'm not much a node.js/npm expert, so guidance would be appreciated.

Or should I just forget Jsonata and move some Javascript code in a function node ?


Easy to reproduce with

[{"id":"e6888c350c73926b","type":"inject","z":"e486c4ba444f3570","name":"$number(\"0x12\")","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"$number(\"0x12\")","payloadType":"jsonata","x":340,"y":820,"wires":[["3f49c7d928059338"]]},{"id":"3f49c7d928059338","type":"debug","z":"e486c4ba444f3570","name":"debug 26","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":540,"y":820,"wires":[]}]



Try $parseInteger("0x12", '0')

I can't confirm if this is a node-red or error from JSONata, Maybe ask on the JSONata git issue page.

[edit] it does look like that is a new JSONata 2 added support for hex numbers.

  • Add support for parsing binary, octal & hexadecimal numbers (PR #573)

I think Nick and team are adding 2.0 in the summer, as far as i can remember.

Works perfectly so it doesn't seems to be v2

Indeed it was the last function on the same doc page but I didn't thought of scolling down as the 1st one look like it was good :slight_smile:

Thanks a lot @E1cid

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