JSON parsing issues due to locale?

I'm trying to use the json node to parse the string from a GET request, which is properly formatted.

The problem seems to be that I get some floating point numbers with decimal point ".", but my locale is using decimal comma "," instead, so I get a JSON parsing error.

Is there no option in the node (or in the JSON.parse() function) to solve that? I'm assuming that replacing the points by commas in the JSON string will mess up the whole thing.

I had a similar issue with the text input node set to input numbers, when I try to type a number with a decimal fraction using the keyboard it will type a point "." despite my locale using a comma, so NR will not accept it as a valid number. I must use the comma in the regular keyboard (next to the "M") so the number is accepted.

My NR server might need an exorcism.

What is it that is putting the invalid JSON there in the first place?

A simple regex should replace the commas
e.g.

[{"id":"e84eb60a.92a638","type":"inject","z":"bf9e1e33.030598","name":"Switch ON","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[    {        \"name\": \"artesium\",        \"amount_final\": 20,        \"tincture_con\": 2,00,        \"tincture_abv\": 60,        \"tincture_needed\": 0.1,        \"ethanol_fraction\": 0.6,        \"ethanol_absolute\": 0.06    }]","payloadType":"str","x":150,"y":2020,"wires":[["c5bfcd6b.8ceed"]]},{"id":"c5bfcd6b.8ceed","type":"change","z":"bf9e1e33.030598","name":"","rules":[{"t":"change","p":"payload","pt":"msg","from":"(?<=\\d+),(?=\\d+)","fromt":"re","to":".","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":350,"y":2020,"wires":[["add8d674.50adf8"]]},{"id":"add8d674.50adf8","type":"json","z":"bf9e1e33.030598","name":"","property":"payload","action":"","pretty":false,"x":570,"y":2040,"wires":[["9c2dee49.d0ea98"]]},{"id":"9c2dee49.d0ea98","type":"debug","z":"bf9e1e33.030598","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":740,"y":1960,"wires":[]}]

It's a GET request to an API, it sends a JSON with two arrays that contain a command history for mobile robots.

If I don't do anything, the object is usually valid, I can fetch the last command from the array, and get the data for that one.

However, if I reboot the server, what I get is an object with two empty arrays, and that starts causing problems.

msg.payload.historicalEntries.length returns undefined (shouldn't it be zero?).

If I try to process the feedback from the API as a string and then parse it in NR, then I get this JSON parse error.

Show us what it looks like in a debug node.

Okay, I took a different approach now:

I use the json node to handle the output, and a change node to set msg.payload = msg.payload.historicalEntries[0] with deep copy.

If the array is not empty, it works well, I get the object with the last command data, add the details to the machine object and continue with the flow.

If the array is empty, then msg.payload will be undefined. In this case, I can ignore the historical command array, specify that the server has been rebooted and there is no historical data, and continue along the flow.

This solves my original issue.

As for the JSON parsing issue, now it does seem to work properly. Strange :confused:

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