Skip to content
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

Change Nested Array value #1202

Closed
gednz opened this issue Mar 4, 2020 · 2 comments
Closed

Change Nested Array value #1202

gednz opened this issue Mar 4, 2020 · 2 comments
Labels
question v6 ArduinoJson 6

Comments

@gednz
Copy link

gednz commented Mar 4, 2020

Hi Benoit

Love your work!

I currently declare the following globally so that I can add data from various functions to dataa:

const char*  DEVICEID = "DevGW";
StaticJsonDocument<300> doca;
JsonArray devicea = doca.createNestedArray(DEVICEID); 
JsonObject dataa = devicea.createNestedObject();

My problem is that I want to store the DEVICEID value in an eeprom which I can't access before setup()
Is it possible to change the DEVICEID value after declaring the NestedArray?

Regards
Gerald

@bblanchon
Copy link
Owner

Hi @gednz,

No, it's currently not possible to change a key or rename a member (requested in issue #979)
It wouldn't be too hard to implement, but I doubt the usefulness of this feature.

Are you sure there isn't a more straightforward solution to your problem?
Why (and how) do you need to create the JsonDocument before setup()?
It looks like you're using a global JsonDocument, are you aware of the problems with a global document?
Why don't you delay the creation of the document until you get all the data?

Best regards,
Benoit

@gednz
Copy link
Author

gednz commented Mar 5, 2020

Hi Benoit

Thanks for clearing that up.

My routine was to directly collect data in various functions using dataa["R"] = rssi; and then when ready to transmit serializeJson(doc, output);. I always did a doc.clear() when done and never had any issues.
I can change to declaring the jsondocuments in a "sampling" function and call sub functions with return values from there. Once that completes I can then serialize to a global char before exiting.

Regards
Gerald

@lock lock bot locked as resolved and limited conversation to collaborators Apr 19, 2020
@bblanchon bblanchon added the v6 ArduinoJson 6 label Feb 6, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
question v6 ArduinoJson 6
Projects
None yet
Development

No branches or pull requests

2 participants