double and long long) in an additional slotserializeJson() et al.ARDUINOJSON_USE_DOUBLE to 0 by default on 8-bit architecturescontainsKey() in favor of doc["key"].is<T>()\' (issue #2124)| Architecture | before | after |
|---|---|---|
| 8-bit | 8 bytes | 6 bytes |
| 32-bit | 16 bytes | 8 bytes |
| 64-bit | 24 bytes | 16 bytes |
BREAKING CHANGES
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.Cpp
// Before if (doc.containsKey("value")) { int value = doc["value"]; // ... } // After if (doc["value"].is<int>()) { int value = doc["value"]; // ... }
ARDUINOJSON_STRING_LENGTH_SIZE to the namespace namedeserializeMsgPack()JsonVariant as a key or index (issue #2080)
Note: works only for reading, not for writingElementProxy and MemberProxy in JsonDocument's constructorARDUINOJSON_USE_LONG_LONG is 0
(they are set to null if they don't fit in a long)JSON_STRING_SIZE(N) return N+1 to fix third-party code (issue #2054)char or char* (issue #2043)poolIndex < count_ after JsonDocument::clear() (issue #2034)JsonObjectConst::operator[] (issue #2019)volatile bool serialized as 1 or 0 instead of true or false (issue #2029)BasicJsonDocumentStaticJsonDocumentAllocator classDynamicJsonDocument with JsonDocumentJSON_ARRAY_SIZE(), JSON_OBJECT_SIZE(), and JSON_STRING_SIZE()ARDUINOJSON_ENABLE_STRING_DEDUPLICATION (string deduplication cannot be disabled anymore)JsonDocument::capacity()serialized("string") by copy (#1915)deserializeJson() and deserializeMsgPack()to<JsonVariant>()size() in serializeMsgPack()ARDUINOJSON_SLOT_OFFSET_SIZE in the namespace nameJsonVariant::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 recycledJsonDocument::memoryUsage()JsonDocument::garbageCollect()deserializeJson(JsonVariant, ...) and deserializeMsgPack(JsonVariant, ...) (#1226)shrinkToFit() in deserializeJson() and deserializeMsgPack()serializeJson() and serializeMsgPack() replace the content of std::string and String instead of appending to itadd() with add<T>() (add(T) is still supported)createNestedArray() and createNestedObject() (use to<JsonArray>() and to<JsonObject>() instead)BREAKING CHANGES
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.
JsonDocumentIn 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, soStaticJsonDocumentandDynamicJsonDocumenthave been merged intoJsonDocument.In ArduinoJson 6,
JsonDocumenthad 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.C++
// ArduinoJson 6 StaticJsonDocument<256> doc; // or DynamicJsonDocument doc(256); // ArduinoJson 7 JsonDocument doc;In ArduinoJson 7,
JsonDocumentreuses 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.Custom allocators
In ArduinoJson 6, you could specify a custom allocator class as a template parameter of
BasicJsonDocument.
In ArduinoJson 7, you must inherit fromArduinoJson::Allocatorand pass a pointer to an instance of your class to the constructor ofJsonDocument.C++
// ArduinoJson 6 class MyAllocator { // ... }; BasicJsonDocument<MyAllocator> doc(256); // ArduinoJson 7 class MyAllocator : public ArduinoJson::Allocator { // ... }; MyAllocator myAllocator; JsonDocument doc(&myAllocator);
createNestedArray()andcreateNestedObject()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:C++
// ArduinoJson 6 arr.createNestedArray(); arr.createNestedObject(); // ArduinoJson 7 arr.add<JsonArray>(); arr.add<JsonObject>();And to create
{"array":[],"object":{}}, you would write:C++
// ArduinoJson 6 obj.createNestedArray("array"); obj.createNestedObject("object"); // ArduinoJson 7 obj["array"].to<JsonArray>(); obj["object"].to<JsonObject>();
cd4b2b2463079785e25312a478ce1570a5073729
idf.py add-dependency "bblanchon/arduinojson^7.2.0"