-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ability to serialize just the keys or just the values. This would be very useful when both json and csv are needed. #2058
Comments
I was able to obtain primitive CSV_Keys and CSV_Values from an ArduinoJson document with the following mods to JsonSerializer.hpp: I added the following variable to the namespace:
I then renamed
This seems to do exactly what I wanted (for the kind of data and structures where it could make sense), as shown by the following example:
Producing the following output:
I'm not submitting a pull request because I know you curate your code very meticulously -- there are better ways to achieve this, obviously, and probably plenty of variant cases to think about. I simply put it out here as food for thought. Thanks! Craig |
Hi Craig,
This function exists; it's size_t n = serializeJson(kv.value(), writePtr); Then, you can use the return value to advance the writing pointer (ensure you don't overflow). Best regards, |
Hi Benoit,
I ran into an edge situation in which I couldn't quite figure out how to meet my needs with AJ. Perhaps I've just overlooked an existing solution, but I've tried everything I could find in the documentation without success. Here's the story:
In my scenario I send serialized json strings from a medical device to a host console. Everything being sent is a flat structure (zero nesting) where all the keys are const char* and the values could be of any type. AJ has been perfect for this for a long time (with one small exception that we discussed several years ago and for which I have a workaround).
I now need to serialize the exact same data in CSV format -- I'll both transmit it to a host and write it to an SD card.
For obvious reasons I'd prefer not to have to maintain two separate serialization lists -- it would be quite useful to be able to serialize the header row and subsequent data rows directly from the same jsonDocument that I already have.
Iterating over kv pairs of the jsonObject allows me to construct the header because the keys are all of type char*. However, I didn't find any obvious way to invoke serialization on the values, which may be of any jsonvariant type. At first I hoped that
kv.value().as<const char*>
would do the trick, but that turns out to be a cast and not a serialization. A function likekv.value.serialize()
would make the kv pair iteration much more useful.I would wrap this into calls like
serializeCsvKeys(jsonDoc, charArray)
andserializeCsvValues(jsonDoc, charArray)
.Sadly I'm still on AJ6 because AJ7 pushed me over the limit of my available space on this Teensy 3.6 project.
Thanks for everything!!
The text was updated successfully, but these errors were encountered: