Why is the input modified?
The JSON parser works in two different modes, depending on whether the input is read-only or not.
Mode 1: read-only input
The read-only mode is used when the JSON input has one of the following types:
const char *
std::string
std::istream
String
Stream
const __FlashStringHelper*
In this mode, the parser copies relevant pieces of the input in the JsonBuffer
.
Examples:
const char* json = "{\"hello\":\"world\"}";
jsonBuffer.parseObject(json);
String json = "{\"hello\":\"world\"}";
jsonBuffer.parseObject(json);
Mode 2: zero-copy
The zero-copy mode is used when the JSON input has one of the following types:
char*
char[]
In this mode, the JSON parser modifies the input in-place. The following modifications are performed:
'\0'
are inserted at the end of each string- Escaped special characters (like
\n
) are unescaped
Example:
char[] json = "{\"hello\":\"world\"}";
jsonBuffer.parseObject(json);
After executing the line above, the input
variable probably contains something like: "hello\0world\0"
.