Custom Serialize json document

I'd like to know if is there a way to serialize a Json doc selecting the key-value pairs instead of serializing all the document, using arduino json library.

thanks

look at filters

āžœ ArduinoJson 6.15: Filtering done right | ArduinoJson

that's what I need, but filters only available on deserialize.

sorry I misread

so you want to built a JSON just using some key/values out of another JSON?

yes, I need to take the valid key/value pairs of a JSON and serialize it to send it by serial comunication.

Isn't that the same as building a JSON document from any other source data and then serializing it? Can you give an example of the resulting JSON? Or the source JSON and which pairs are 'valid'?

since the JSON doc will be changing on amount of members, could I build a JSON with the valid data and after use it, destroy the JSON doc for the next time create a new one, is that possible?

the JSON will be something like this ```
{"temperature":21.2,"humidity":68.9,"pressure":1003}

For something like that, you barely need to use a JSON object. You can just print the text and variables directly to the serial port.

The ArduinoJson.org 'Assistant' says you would create your JSON document this way:

StaticJsonDocument<48> doc;

doc["temperature"] = 21.2;
doc["humidity"] = 68.9;
doc["pressure"] = 1003;

serializeJson(doc, output);

You can then use doc.clear(); to empty the document and reset the memory pool. (StaticJsonDocument | ArduinoJson 6)

Thanks, I will try that way.

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