ArduinoJson icon indicating copy to clipboard operation
ArduinoJson copied to clipboard

deserializeJson(JsonVariant, ...)

Open Michel-Ketelaars opened this issue 5 years ago • 4 comments

It would be nice if the functions / methods serialzeJson() and deserializeJson() would be extended, so that it is possible to use them directly on nested Objects (and not only on the Json document). What I mean is extra function overloadings like this: size_t serializeJson(const JsonObject& object, char output[size]); deserializeJson(JsonObject& object, char* input);

For my MQTT project it would be very handy, because I have to serialise a portion of a json object.

Michel-Ketelaars avatar Mar 29 '20 11:03 Michel-Ketelaars

Hi @Michel-Ketelaars,

The first is already supported, you can do that for example:

serializeJson(doc["config"], configFile);

Can you detail the use case for deserializeJson(JsonObject&,...)?

Best regards, Benoit

bblanchon avatar Mar 29 '20 14:03 bblanchon

Hi Benoit,

Thanks for your reply and good to hear that this is already supported for the serialization part.

I indeed tested only the deserializeJson() function and assumed this was also not implemented in serializeJson() function, because I did not see the particular overloaded function under Signatures. (https://arduinojson.org/v6/api/json/serializejson/)

The use case is that I receive a Json serialized message from an MQTT server with several values that I want to add or change into an existing Json opject that is afterward is completely published to a webservice.

Best regards, Michel

Michel-Ketelaars avatar Mar 29 '20 15:03 Michel-Ketelaars

I want to add or change into an existing Json object

If you do this repeatedly, it will create a memory leak. How do you plan to mitigate this?

bblanchon avatar Apr 01 '20 07:04 bblanchon

@Michel-Ketelaars, would #1343 provide an acceptable solution to your use case?

bblanchon avatar Sep 20 '20 13:09 bblanchon

I just implemented this feature in branch 7.x.

bblanchon avatar Jul 29 '23 13:07 bblanchon