Description
I do not think this is a bug within ArduinoJson, seeking help from anyone with similar experience
Note - I am able to parse the json by reading the stream char-by-char into an array (and deleting some code/functionaliy to have enough memory)
Describe the bug
When passing http.getStream() to deserialize a large payload, I am getting InvalidInput
error.
The json that i am parsing is ~88k, which I understand exceeds the maximum string size for esp32 (65k) (using xiao esp32c3).
Therefore I tried to use http.getStream so that the json isn't duplicated in memory.
I tried Serial.println(http.getStream().readString());
and this failes validation, the complete json is there but there are some characters our of order (cURL to the API & json validation passes).
Given that getStream().readString() is returning a bad string, this doesn't seem to be an arduino json issue, but wanted to ask here to confirm and see if there was a work around.
Troubleshooter report
Here is the report generated by the ArduinoJson Troubleshooter:
- The program uses ArduinoJson 7
- The issue happens at run time
- The issue concerns deserialization
deserializeJson()
returnsInvalidInput
- Input comes from a stream
- *
jsonlint
says the document is valid (when using cURL, invalid data returned by http.getStream() - Adding a buffer doesn't solve the issue
- Input's first byte doesn't suggest a BOM
Environment
Here is the environment that I used:
- Microcontroller: XIAO ESP32C3
- Core/runtime: Arduino
- IDE: Arduino IDE 2.3.4
Reproduction
Here is a small snippet that reproduces the issue.
HTTPClient http;
client.setInsecure();
client.setTimeout(20000);
http.useHTTP10(true);
http.begin(client, url);
http.GET();
// Parse response
JsonDocument filter;
JsonObject filter_fixtures_0 = filter["fixtures"].add<JsonObject>();
filter_fixtures_0["id"] = true;
filter_fixtures_0["time"] = true;
filter_fixtures_0["status"] = true;
filter_fixtures_0["date"] = true;
DynamicJsonDocument doc(32768);
ReadBufferingStream bufferedStream(http.getStream(), 64);
DeserializationError error = deserializeJson(doc, bufferedStream, DeserializationOption::Filter(filter));
http.end();
if (error) {
Serial.println("JSON parse failed: " + String(error.c_str()));
return false;
}
Compiler output
n/a
Program output
JSON parse failed: IncompleteInput