Transforming the serial message into a json object

Good morning, I need to take a serial message that the arduino sends me on usb and transfer it to a database (influxdb) Making it readable
Type: sensor: 20
sensor2: 35

Welcome to the forum @comkin

I presume that you mean that you want to convert it to a javascript object (there is no such thing as a JSON object, JSON is a string).

If you have control of the arduino code that the best way is to format the data as a JSON string and send that back via the serial port. Then you can feed it straight into a JSON node to convert it from JSON to a javascript object.

1 Like

Sorry, I have never used these languages.

Is the json string format to be written to the arduino OK?
like: "sensor1", "value"; (with all punctuation)


You want something like this
{"sensor1": 7}
or if you have multiple sensors
{"sensor1": 7, "sensor2": 23.5}

the second one
i need this:
from this:

That is not valid JSON.

Once you have properly formatted JSON coming from Arduino into node-red it is very simple to use.

See this for how to correctly send JSON : How to do serial communication between two boards? | ArduinoJson 6

1 Like

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