I have some structs in my app, and in some cases structs within structs to organize the data efficiently. I’m have a requirement to serialize that struct to Json and then to be able to deserialize the Json to a string.
I believe the latter can be achieved with @rickkas7 JsonParserGeneratorRK library, but looking for recommendations on how to take the struct and convert it to Json.
There is no automated way of doing it, you just need to convert each member in your struct to and from JSON primitive types (int, bool, float, string, etc.), inner objects (struct in struct) and arrays. And of course do the reverse for deserialization.
If you wanted to store the resulting JSON in a char array you could use snprintf, and if you wanted to parse the JSON char array back into the struct you could use sscanf.
In a lot of my projects when I need to format my data as JSON into a char buffer so that I can publish it I’ll use snprintf. While decoding JSON can be done in firmware with sscanf, if the JSON is coming from a webhook I usually try to reorganize the JSON into a comma separated string using mustache templates so that it’s easier to parse out the data I want in the firmware.