Is it possible?
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?
Option 1: Parse the stream in chunk
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
"forecastday": [ is found (use
Stream::find()), and then parse the objects for each day one after the other.
Option 2: bye-bye ArduinoJson
The library json-streaming-parser takes an entirely different approach to ArduinoJson, which makes it suitable for this kind of problems.