-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Closed
Labels
Milestone
Description
Describe the bug
Not sure if a bug or a design choice. But this is the workflow to reproduce this issue:
- Use ArduinoJSON V6
- Create a JsonDocument with fixed size (static or dynamic).
- Create a JsonArray inside that JsonDocument.
- Create a loop that fills the JsonArray with JsonObjects like this
{"id":3,"test":"this is a test", "another_key":"random text"}
- The loop exits when
JsonArray.add()
returns false (no more memory in the JsonDocument to add another item in the array).
When checking what was saved in the JsonArray, I find something like this:
[
{"id":3,"test":"this is a test", "another_key":"random text"},
{"id":3,"test":"this is a test", "another_key":"random text"},
{"id":3,"test":"this is a test", "another_key":"random text"},
{"id":3,"test":"this is a test", "another_key":"random text"},
{"id":3} <--- PARTIAL JSON!!
]
It seems that when you call the method add()
it returns false if there's no more memory to fully add the JsonObject, but it leaves a partial JSON in the array. I think this should not be the correct behavior. It should notify if there's not enough memory to store the JsonObject but leave the array untouched. Adding a partial JSON probably is a bad idea in most situations (API breaker).