Is it possible?
Yes, but not in one shot.
By design, ArduinoJson stores the complete representation of the JSON object tree in memory.
If you use the zero-copy mode (mutable input), the whole JSON input must stay in memory.
How to solve?
One cool feature of ArduinoJson is that, when it parses an object from a
Stream, it stops reading when it encounters the closing
}, and the same is true for arrays.
This feature allows to parse streams in chunks, you just need to call
JsonBuffer::parseObject() in a loop.
Of course, don’t forget to skip the commas (
,) between the objects.
As usual, don’t reuse the
JsonBuffer, declare it inside the loop.
For example, if you want to parse the huge response of a 10-day forecast of Weather Underground, you can skip the beginning until you see
"forecastday": [ in the stream (use
Stream::find()), and then parse the objects for each day one after the other.
- Mastering ArduinoJson (free ebook), chapter Case Studies