BasicJsonDocument::shrinkToFit()uint8_t for serializeJson(), serializeJsonPretty(), and serializeMsgPack() (issue #1142)ARDUINOJSON_ENABLE_COMMENTS to enable support for comments (defaults to 0)std::string and std::stream on modern compilers (issue #1156)
(No need to define ARDUINOJSON_ENABLE_STD_STRING and ARDUINOJSON_ENABLE_STD_STREAM anymore)measureJson, measureJsonPretty, and measureMsgPack to keywords.txt
(This file is used for syntax highlighting in the Arduino IDE)variant.is<nullptr_t>()serializeJson(), serializeJsonPretty(), and serializeMsgPack() when writing to a StringserializeJson(), serializeJsonPretty(), and serializeMsgPack() when writing to a StringBREAKING CHANGES
Comments
Support for comments in input is now optional and disabled by default.
If you need support for comments, you must defined
ARDUINOJSON_ENABLE_COMMENTSto1; otherwise, you'll receiveInvalidInputerrors.#define ARDUINOJSON_ENABLE_COMMENTS 1 #include <ArduinoJson.h>
JsonArray and JsonObject to bool, to be consistent with JsonVariantdeserializeJson() when input contains duplicate keys (issue #1095)deserializeMsgPack() speed by reading several bytes at once0xFF (PR #1118 by @mikee47)MemberProxy and ElementProxy (issue #1120)JsonVariant::as<bool>() to return true for any non-null value (issue #1005)extras/ (issue #1011)strlen_P(), strncmp_P(), strcmp_P(), and memcpy_P() (issue #1073)measureJson() to the ArduinoJson namespace (PR #1069 by @nomis)basic_string<char, traits, allocator> (issue #1045)JsonConfigFile.ino for ESP8266Arduino.h if ARDUINO is defined (PR #1071 by @nomis)== and != for JsonDocument, ElementProxy, and MemberProxyJsonVariant when one contains a linked string and the other contains an owned string (issue #1051)JsonDocument to JsonVariant (issue #1023)serialized() not working with Flash strings (issue #1030)deserializeJson() silently accepting a Stream* (issue #978)operator| (issue #981)deserializeJson() more picky about trailing characters (issue #980)ARDUINOJSON_ENABLE_NAN (default=0) to enable NaN in JSON (issue #973)ARDUINOJSON_ENABLE_INFINITY (default=0) to enable Infinity in JSONJsonVariantnullptr (issue #998)BREAKING CHANGES
NaN and Infinity
The JSON specification allows neither NaN not Infinity, but previous versions of ArduinoJson supported it. Now, ArduinoJson behaves like most other libraries: a NaN or and Infinity in the
JsonDocument, becomes anullin the output JSON. Also,deserializeJson()returnsInvalidInputif the JSON document contains NaN or Infinity.This version still supports NaN and Infinity in JSON documents, but it's disabled by default to be compatible with other JSON parsers. If you need the old behavior back, define
ARDUINOJSON_ENABLE_NANandARDUINOJSON_ENABLE_INFINITYto1;:#define ARDUINOJSON_ENABLE_NAN 1 #define ARDUINOJSON_ENABLE_INFINITY 1 #include <ArduinoJson.h>The "or" operator
This version slightly changes the behavior of the | operator when the variant contains a float and the user requests an integer.
Older versions returned the floating point value truncated. Now, it returns the default value.
// suppose variant contains 1.2 int value = variant | 3; // old behavior: value == 1 // new behavior value == 3If you need the old behavior, you must add
if (variant.is<float>()).
deserializeJson() not being picky enough (issue #969)JsonVariant::as<T>() and JsonVariant::is<T>().
as<T>() returns 0 if the integer T overflowsis<T>() returns false if the integer T overflowsBasicJsonDocument to support custom allocator (issue #876)JsonDocument::containsKey() (issue #938)JsonVariant::containsKey()StaticJsonBuffer and DynamicJsonBufferJsonArray::copyFrom()/copyTo() to free functions copyArray()JsonArray::copyFrom() and JsonObject::copyFrom() to set()JsonArray::get() to getElement()JsonArray::add() (without arg) to addElement()JsonObject::get() to getMember()JsonObject::getOrCreate() to getOrAddMember()JsonVariant::isNull() not returning true after set((char*)0)variant.set(serialized((char*)0))IncompleteInput in false, true, and nullJsonDocument::size()JsonDocument::remove()JsonVariant::clear()JsonVariant::remove()DynamicJsonDocumentJsonArray::copyFrom() accepts JsonArrayConstJsonVariant::set() accepts JsonArrayConst and JsonObjectConstJsonDocument was missing in the ArduinoJson namespacememoryUsage() to JsonArray, JsonObject, and JsonVariantnesting() to JsonArray, JsonDocument, JsonObject, and JsonVariantJsonDocument::nestingLimit with an additional parameter
to deserializeJson() and deserializeMsgPack()JsonDocumentStaticJsonDocument copy constructor and copy assignmentDynamicJsonDocument chooses the capacity according to the memory usage of the source, not from the capacity of the source.StaticJsonDocument/DynamicJsonDocument from a JsonArray/JsonObject/JsonVariantJsonDocument::isNull()JsonDocument::operator[]ARDUINOJSON_TAB to configure the indentation characteradd(), createNestedArray() and createNestedObject() to JsonVariantJsonVariant automatically promotes to JsonObject or JsonArray on write.
Calling JsonVariant::to<T>() is not required anymore.JsonDocument now support the same operations as JsonVariant.
Calling JsonDocument::as<T>() is not required anymore.JsonHttpClient.inoJsonString as a key or a valueBREAKING CHANGES
DynamicJsonDocument's constructorThe parameter to the constructor of
DynamicJsonDocumentis now mandatoryOld code:
DynamicJsonDocument doc;New code:
DynamicJsonDocument doc(1024);Nesting limit
JsonDocument::nestingLimitwas replaced with a new parameter todeserializeJson()anddeserializeMsgPack().Old code:
doc.nestingLimit = 15; deserializeJson(doc, input);New code:
deserializeJson(doc, input, DeserializationOption::NestingLimit(15));
DynamicJsonDocument, it now has a fixed capacity.JsonKey to JsonStringJsonArray::is<T>(i) and JsonArray::set(i,v)JsonObject::is<T>(k) and JsonObject::set(k,v)T JsonArray::get<T>(i) with JsonVariant JsonArray::get(i)T JsonObject::get<T>(k) with JsonVariant JsonObject::get(k)JSON_STRING_SIZE()DeserializationError::code() to be used in switch statements (issue #846)JsonArray and JsonObject to JsonVariantJsonPair::key() now returns a JsonKeyDynamicJsonDocumentJsonVariant::is<String>() (closes #763)JsonArrayConst, JsonObjectConst, and JsonVariantConstJsonDocument (issue #827)JsonArray and JsonObject, instead of storing pointers (issue #780)JsonVariant::to<JsonArray>() and JsonVariant::to<JsonObject>()JsonVariantJsonPair's key and value with key() and value()serializeJson(obj[key], dst) (issue #794)BREAKING CHANGES
JsonVariant
JsonVariantnow has a semantic similar toJsonObjectandJsonArray. It's a reference to a value stored in theJsonDocument. As a consequence, aJsonVariantcannot be used as a standalone variable anymore.Old code:
JsonVariant myValue = 42;New code:
DynamicJsonDocument doc; JsonVariant myValue = doc.to<JsonVariant>(); myValue.set(42);JsonPair
Old code:
for(JsonPair p : myObject) { Serial.println(p.key); Serial.println(p.value.as<int>()); }New code:
for(JsonPair p : myObject) { Serial.println(p.key()); Serial.println(p.value().as<int>()); }CAUTION: the key is now read only!
invalid application of 'sizeof' to incomplete type '__FlashStringHelper' (issue #783)char[] not duplicated when passed to JsonVariant::operator[]JsonObject not inserting keys of type String (issue #782)JsonVariant::is<int>() that returned true for empty strings-fsingle-precision-constant is usedRawJson() to serialized()serializeMsgPack() now supports values marked with serialized()BREAKING CHANGES
Non quoted strings
Non quoted strings are now forbidden in values, but they are still allowed in keys. For example,
{key:"value"}is accepted, but{key:value}is not.Preformatted values
Old code:
object["values"] = RawJson("[1,2,3,4]");New code:
object["values"] = serialized("[1,2,3,4]");
JsonArray and JsonObject by value instead of reference (issue #309)success() with isNull()BREAKING CHANGES
Old code:
JsonObject& obj = doc.to<JsonObject>(); JsonArray& arr = obj.createNestedArray("key"); if (!arr.success()) { Serial.println("Not enough memory"); return; }New code:
JsonObject obj = doc.to<JsonObject>(); JsonArray arr = obj.createNestedArray("key"); if (arr.isNull()) { Serial.println("Not enough memory"); return; }
isnan() and isinf() macros (issue #752)DynamicJsonDocument and StaticJsonDocumentdeserializeJson()serializeJson() and serializeJsonPretty()measureJson() and measureJsonPretty()serializeMsgPack(), deserializeMsgPack() and measureMsgPack() (issue #358)MsgPackParser.ino (issue #358)JsonBuffer::parseArray(), parseObject() and parse()JsonBuffer::createArray() and createObject()printTo() and prettyPrintTo()measureLength() and measurePrettyLength()BREAKING CHANGES
Deserialization
Old code:
DynamicJsonBuffer jb; JsonObject& obj = jb.parseObject(json); if (obj.success()) { }New code:
DynamicJsonDocument doc; DeserializationError error = deserializeJson(doc, json); if (error) { } JsonObject& obj = doc.as<JsonObject>();Serialization
Old code:
DynamicJsonBuffer jb; JsonObject& obj = jb.createObject(); obj["key"] = "value"; obj.printTo(Serial);New code:
DynamicJsonDocument obj; JsonObject& obj = doc.to<JsonObject>(); obj["key"] = "value"; serializeJson(doc, Serial);
JsonBuffer::parse() not respecting nesting limit correctly (issue #693)strcmp() (PR #745 from Mike Karlesky)ARDUINOJSON_VERSION, ARDUINOJSON_VERSION_MAJOR...JsonVariant::operator|(int) that returned the default value if the variant contained a double (issue #675)RawJson() accepts any kind of string and obeys to the same rules for duplicationstrdup() to const char* to prevent double duplicationstrdup() as deprecatedNew rules for string duplication
type duplication const char* no char* noyesString yes std::string yes const __FlashStringHelper* yes These new rules make
JsonBuffer::strdup()useless.
JsonVariant::operator| to return a default value (see below)How to use the new feature?
If you have a block like this:
const char* ssid = root["ssid"]; if (!ssid) ssid = "default ssid";You can simplify like that:
const char* ssid = root["ssid"] | "default ssid";
DynamicJsonBuffer::clear() not resetting allocation size (issue #561)PGM_P as Particle 0.6.2 doesn't define it (issue #546)ARDUINOJSON_DOUBLE_IS_64BITS as it became useless.JsonBuffer non-copyable (PR #524 by @luisrayas3)StaticJsonBuffer::clear()DynamicJsonBuffer::clear()ARDUINOJSON_DOUBLE_IS_64BITSARDUINOJSON_EMBEDDED_MODE1e7 and 1e-5 (issues #288, #427 and #506)JsonVariant::is<double>() now returns true for integersIsBaseOf is not a member of ArduinoJson::TypeTraits (issue #495)forming reference to reference (issue #495)BREAKING CHANGES :warning:
Old syntax New syntax double_with_n_digits(3.14, 2)3.14float_with_n_digits(3.14, 2)3.14fobj.set("key", 3.14, 2)obj["key"] = 3.14arr.add(3.14, 2)arr.add(3.14)
Input Old output New output 3.141593.143.1415942.042.00420.00.000
Expression Old result New result JsonVariant(42).is<int>()truetrueJsonVariant(42).is<float>()falsetrueJsonVariant(42).is<double>()falsetrue
JsonArray::remove(iterator) (issue #479)JsonObject::remove(iterator)JsonArray::removeAt(size_t) into remove(size_t)include/ to src/floating constant exceeds range of floatand floating constant truncated to zero (issue #483)Print class and converted printTo() to a template method (issue #276)IndentedPrintExample.inostrtod() (issue #453)strtol() (issue #465)char is now treated as an integral type (issue #337, #370)DynamicJsonBuffer when memory allocation fails (issue #433)== and != for two JsonVariants (issue #436)JsonVariant::operator[const FlashStringHelper*] (issue #441)Stream timeout (issue #422)JsonObject is a char[] (issue #423)const referencesunsigned char* (issue #428)deprecated attribute on asArray(), asObject() and asString() (issue #420)volatile int to a JsonVariant (issue #415)ARDUINOJSON_ENABLE_STD_STREAM and ARDUINOJSON_ENABLE_ARDUINO_STREAM are set to 1== to compare JsonVariant and strings (issue #402)Stream (issue #300)BREAKING CHANGES :warning:
JsonBuffer::parseObject()andJsonBuffer::parseArray()have been pulled down to the derived classesDynamicJsonBufferandStaticJsonBufferBase.This means that if you have code like:
void myFunction(JsonBuffer& jsonBuffer);you need to replace it with one of the following:
void myFunction(DynamicJsonBuffer& jsonBuffer); void myFunction(StaticJsonBufferBase& jsonBuffer); template<typename TJsonBuffer> void myFunction(TJsonBuffer& jsonBuffer);
printTo(char[N]) and prettyPrintTo(char[N]) (issue #292)root["A"]["B"] = "C" (issue #352)*.ipp to *Impl.hpp because they were ignored by Arduino IDE (issue #396)String or std::stringArduinoJson::StringJsonVariant::defaultValue<T>()JsonObject::get() and JsonArray.get()StringSumHelper (issue #184)ARDUINOJSON_USE_ARDUINO_STRING by ARDUINOJSON_ENABLE_STD_STRING and ARDUINOJSON_ENABLE_ARDUINO_STRING (issue #378)StringExample.ino to show where String can be usedBREAKING CHANGES :warning:
The non-template functions
JsonObject::get()andJsonArray.get()have been removed. This means that you need to explicitely tell the type you expect in return.Old code:
#define ARDUINOJSON_USE_ARDUINO_STRING 0 JsonVariant value1 = myObject.get("myKey"); JsonVariant value2 = myArray.get(0);New code:
#define ARDUINOJSON_ENABLE_ARDUINO_STRING 0 #define ARDUINOJSON_ENABLE_STD_STRING 1 JsonVariant value1 = myObject.get<JsonVariant>("myKey"); JsonVariant value2 = myArray.get<JsonVariant>(0);
array[idx].as<JsonVariant>() and object[key].as<JsonVariant>()JsonObject::set() (issue #350)Prettyfier and Print (issue #354)+ (issue #349)-Wparentheses warning introduced in v5.6.5 (PR #335 by @nuket).mbedignore for ARM mbdeb (PR #334 by @nuket)JsonVariant::success() which didn't propagate JsonArray::success() nor JsonObject::success() (issue #342).as<char*>() now returns true when input is null (issue #330)as<JsonArray>() as a synonym for as<JsonArray&>()... (issue #291)call of overloaded isinf(double&) is ambiguous (issue #284)#undef isnan (issue #284)#pragma once (issue #310)JsonVariant::success() (issue #279)JsonVariant::invalid<T>() to JsonVariant::defaultValue<T>()::String to ArduinoJson::String (issue #275)::Print to ArduinoJson::Print tooftoa (issues #266, #267, #269 and #270)JsonVariant JsonBuffer::parse() (issue #265)unsigned long printed as signed long (issue #170)JsonVariant::as<char*>() as a synonym for JsonVariant::as<const char*>() (issue #257)JsonHttpClient (issue #256)JsonArray::copyTo() and JsonArray::copyFrom() (issue #254)RawJson() to insert pregenerated JSON portions (issue #259)long long (issue #171)ArduinoJson/Configuration.hppBREAKING CHANGE :warning:
If you defined
ARDUINOJSON_ENABLE_STD_STREAM, you now need to define it to1.
JsonVariant::is<bool>() that was incorrectly returning false (issue #214)add_subdirectory(ArduinoJson/src)String to be a typedef of std::string (issues #142 and #161)BREAKING CHANGES :warning:
JsonVariant(true).as<String>()now returns"true"instead of"1"JsonVariant(false).as<String>()now returns"false"instead of"0"
DynamicJsonBuffer constructor to set initial size (issue #152)JsonObjectSuscript::set(value, decimals) (issue #143)float instead of double to reduce the size of JsonVariant (issue #134)JsonArraySubscript and JsonObjectSubscript (issue #122)printTo(String) which wrote numbers instead of strings (issue #120)JsonArray::is<T>() and some others (issue #121)parseObject(String) and parseArray(String), when the
StaticJsonBuffer is too small to hold a copy of the stringString class (issues #55, #56, #70, #77)JsonBuffer::strdup() to make a copy of a string (issues #10, #57)strdup() for String but not for char* (issues #84, #87)JsonVariant to leverage converting constructors instead of assignment operators (issue #66)BREAKING CHANGES :warning:
JsonObject::add()was renamed toset()JsonArray::at()andJsonObject::at()were renamed toget()- Number of digits of floating point value are now set with
double_with_n_digits()
Personal note about the String class:
Support of the String class has been added to the library because many people use it in their programs.
However, you should not see this as an invitation to use the String class.
The String class is bad because it uses dynamic memory allocation.
Compared to static allocation, it compiles to a bigger, slower program, and is less predictable.
You certainly don't want that in an embedded environment!