- Fix support for NUL characters in
deserializeJson()
- Make
ElementProxy
andMemberProxy
non-copyable - Change string copy policy: only string literal are stored by pointer
JsonString
is now stored by copy, unless specified otherwise- Replace undocumented
JsonString::Ownership
withbool
- Rename undocumented
JsonString::isLinked()
toisStatic()
- Move public facing SFINAEs to template declarations
In previous versions,
MemberProxy
(the class returned byoperator[]
) could lead to dangling pointers when used with a temporary string. To prevent this issue,MemberProxy
andElementProxy
are now non-copyable.Your code is likely to be affected if you use
auto
to store the result ofoperator[]
. For example, the following line won't compile anymore:auto value = doc["key"];To fix the issue, you must append either
.as<T>()
or.to<T>()
, depending on the situation.For example, if you are extracting values from a JSON document, you should update like this:
- auto config = doc["config"]; + auto config = doc["config"].as<JsonObject>(); const char* name = config["name"];However, if you are building a JSON document, you should update like this:
- auto config = doc["config"]; + auto config = doc["config"].to<JsonObject>(); config["name"] = "ArduinoJson";
- Forbid
deserializeJson(JsonArray|JsonObject, ...)
(issue #2135) - Fix VLA support in
JsonDocument::set()
- Fix
operator[](variant)
ignoring NUL characters
- Store object members with two slots: one for the key and one for the value
- Store 64-bit numbers (
double
andlong long
) in an additional slot - Reduce the slot size (see table below)
- Improve message when user forgets third arg of
serializeJson()
et al. - Set
ARDUINOJSON_USE_DOUBLE
to0
by default on 8-bit architectures - Deprecate
containsKey()
in favor ofdoc["key"].is<T>()
- Add support for escape sequence
\'
(issue #2124)
Architecture | before | after |
---|---|---|
8-bit | 8 bytes | 6 bytes |
32-bit | 16 bytes | 8 bytes |
64-bit | 24 bytes | 16 bytes |
After being on the death row for years, the
containsKey()
method has finally been deprecated. You should replacedoc.containsKey("key")
withdoc["key"].is<T>()
, which not only checks that the key exists but also that the value is of the expected type.// Before if (doc.containsKey("value")) { int value = doc["value"]; // ... } // After if (doc["value"].is<int>()) { int value = doc["value"]; // ... }
- Add
ARDUINOJSON_STRING_LENGTH_SIZE
to the namespace name - Add support for MsgPack binary (PR #2078 by @Sanae6)
- Add support for MsgPack extension
- Make string support even more generic (PR #2084 by @d-a-v)
- Optimize
deserializeMsgPack()
- Allow using a
JsonVariant
as a key or index (issue #2080) Note: works only for reading, not for writing - Support
ElementProxy
andMemberProxy
inJsonDocument
's constructor - Don't add partial objects when allocation fails (issue #2081)
- Read MsgPack's 64-bit integers even if
ARDUINOJSON_USE_LONG_LONG
is0
(they are set tonull
if they don't fit in along
)
- Make
JSON_STRING_SIZE(N)
returnN+1
to fix third-party code (issue #2054)
- Improve error messages when using
char
orchar*
(issue #2043) - Reduce stack consumption (issue #2046)
- Fix compatibility with GCC 4.8 (issue #2045)
- Fix assertion
poolIndex < count_
afterJsonDocument::clear()
(issue #2034)
- Fix "no matching function" with
JsonObjectConst::operator[]
(issue #2019) - Remove unused files in the PlatformIO package
- Fix
volatile bool
serialized as1
or0
instead oftrue
orfalse
(issue #2029)
- Remove
BasicJsonDocument
- Remove
StaticJsonDocument
- Add abstract
Allocator
class - Merge
DynamicJsonDocument
withJsonDocument
- Remove
JSON_ARRAY_SIZE()
,JSON_OBJECT_SIZE()
, andJSON_STRING_SIZE()
- Remove
ARDUINOJSON_ENABLE_STRING_DEDUPLICATION
(string deduplication cannot be disabled anymore) - Remove
JsonDocument::capacity()
- Store the strings in the heap
- Reference-count shared strings
- Always store
serialized("string")
by copy (#1915) - Remove the zero-copy mode of
deserializeJson()
anddeserializeMsgPack()
- Fix double lookup in
to<JsonVariant>()
- Fix double call to
size()
inserializeMsgPack()
- Include
ARDUINOJSON_SLOT_OFFSET_SIZE
in the namespace name - Remove
JsonVariant::shallowCopy()
JsonDocument
's capacity grows as needed, no need to pass it to the constructor anymoreJsonDocument
's allocator is not monotonic anymore, removed values get recycled- Show a link to the documentation when user passes an unsupported input type
- Remove
JsonDocument::memoryUsage()
- Remove
JsonDocument::garbageCollect()
- Add
deserializeJson(JsonVariant, ...)
anddeserializeMsgPack(JsonVariant, ...)
(#1226) - Call
shrinkToFit()
indeserializeJson()
anddeserializeMsgPack()
serializeJson()
andserializeMsgPack()
replace the content ofstd::string
andString
instead of appending to it- Replace
add()
withadd<T>()
(add(T)
is still supported) - Remove
createNestedArray()
andcreateNestedObject()
(useto<JsonArray>()
andto<JsonObject>()
instead)
As every major release, ArduinoJson 7 introduces several breaking changes. I added some stubs so that most existing programs should compile, but I highty recommend you upgrade your code.
In ArduinoJson 6, you could allocate the memory pool on the stack (with
StaticJsonDocument
) or in the heap (withDynamicJsonDocument
).
In ArduinoJson 7, the memory pool is always allocated in the heap, soStaticJsonDocument
andDynamicJsonDocument
have been merged intoJsonDocument
.In ArduinoJson 6,
JsonDocument
had a fixed capacity; in ArduinoJson 7, it has an elastic capacity that grows as needed. Therefore, you don't need to specify the capacity anymore, so the macrosJSON_ARRAY_SIZE()
,JSON_OBJECT_SIZE()
, andJSON_STRING_SIZE()
have been removed.// ArduinoJson 6 StaticJsonDocument<256> doc; // or DynamicJsonDocument doc(256); // ArduinoJson 7 JsonDocument doc;In ArduinoJson 7,
JsonDocument
reuses released memory, sogarbageCollect()
has been removed.
shrinkToFit()
is still available and releases the over-allocated memory.Due to a change in the implementation, it's not possible to store a pointer to a variant from another
JsonDocument
, soshallowCopy()
has been removed.In ArduinoJson 6, the meaning of
memoryUsage()
was clear: it returned the number of bytes used in the memory pool.
In ArduinoJson 7, the meaning ofmemoryUsage()
would be ambiguous, so it has been removed.In ArduinoJson 6, you could specify a custom allocator class as a template parameter of
BasicJsonDocument
.
In ArduinoJson 7, you must inherit fromArduinoJson::Allocator
and pass a pointer to an instance of your class to the constructor ofJsonDocument
.// ArduinoJson 6 class MyAllocator { // ... }; BasicJsonDocument<MyAllocator> doc(256); // ArduinoJson 7 class MyAllocator : public ArduinoJson::Allocator { // ... }; MyAllocator myAllocator; JsonDocument doc(&myAllocator);In ArduinoJson 6, you could create a nested array or object with
createNestedArray()
andcreateNestedObject()
.
In ArduinoJson 7, you must useadd<T>()
orto<T>()
instead.For example, to create
[[],{}]
, you would write:// ArduinoJson 6 arr.createNestedArray(); arr.createNestedObject(); // ArduinoJson 7 arr.add<JsonArray>(); arr.add<JsonObject>();And to create
{"array":[],"object":{}}
, you would write:// ArduinoJson 6 obj.createNestedArray("array"); obj.createNestedObject("object"); // ArduinoJson 7 obj["array"].to<JsonArray>(); obj["object"].to<JsonObject>();