ArduinoJson 6.18.0 * Added support for custom converters (issue #687) * Added support for `Printable` (issue #1444) * Removed support for `char` values, see below (issue #1498) * `deserializeJson()` leaves `\uXXXX` unchanged instead of returning `NotSupported` * `deserializeMsgPack()` inserts `null` instead of returning `NotSupported` * Removed `DeserializationError::NotSupported` * Added `JsonVariant::is<JsonArrayConst/JsonObjectConst>()` (issue #1412) * Added `JsonVariant::is<JsonVariant/JsonVariantConst>()` (issue #1412) * Changed `JsonVariantConst::is<JsonArray/JsonObject>()` to return `false` (issue #1412) * Simplified `JsonVariant::as<T>()` to always return `T` (see below) * Updated folders list in `.mbedignore` (PR #1515 by @AGlass0fMilk) * Fixed member-call-on-null-pointer in `getMember()` when array is empty * `serializeMsgPack(doc, buffer, size)` doesn't add null-terminator anymore (issue #1545) * `serializeJson(doc, buffer, size)` adds null-terminator only if there is enough room * PlatformIO: set `build.libArchive` to `false` (PR #1550 by @askreet)
Changes since 6.17.3
- Added support for custom converters (issue #687)
- Added support for
Printable(issue #1444) - Removed support for
charvalues, see below (issue #1498) -
deserializeJson()leaves\uXXXXunchanged instead of returningNotSupported -
deserializeMsgPack()insertsnullinstead of returningNotSupported - Removed
DeserializationError::NotSupported - Added
JsonVariant::is<JsonArrayConst/JsonObjectConst>()(issue #1412) - Added
JsonVariant::is<JsonVariant/JsonVariantConst>()(issue #1412) - Changed
JsonVariantConst::is<JsonArray/JsonObject>()to returnfalse(issue #1412) - Simplified
JsonVariant::as<T>()to always returnT(see below) - Updated folders list in
.mbedignore(PR #1515 by @AGlass0fMilk) - Fixed member-call-on-null-pointer in
getMember()when array is empty -
serializeMsgPack(doc, buffer, size)doesn't add null-terminator anymore (issue #1545) -
serializeJson(doc, buffer, size)adds null-terminator only if there is enough room - PlatformIO: set
build.libArchivetofalse(PR #1550 by @askreet)
BREAKING CHANGES
Support for
charremovedWe cannot cast a
JsonVariantto acharanymore, so the following will break:char age = doc["age"]; // error: no matching function for call to 'variantAs(VariantData*&)'Instead, you must use another integral type, such as
int8_t:int8_t age = doc["age"]; // OKSimilarly, we cannot assign from a
charanymore, so the following will break:char age; doc["age"] = age; // error: no matching function for call to 'VariantRef::set(const char&)'Instead, you must use another integral type, such as
int8_t:int8_t age; doc["age"] = age; // OKA deprecation warning with the message "Support for
charis deprecated, useint8_toruint8_tinstead" was added to allow a smooth transition.
as<T>()always returnsTPreviously,
JsonVariant::as<T>()could return a type different fromT. The most common example isas<char*>()that returned aconst char*. While this feature simplified a few use cases, it was confusing and complicated the implementation of custom converters.Starting from this version,
as<T>doesn't try to auto-correct the return type and always returnT, which means that you cannot write this anymore:Serial.println(doc["sensor"].as<char*>()); // error: invalid conversion from 'const char*' to 'char*' [-fpermissive]Instead, you must write:
Serial.println(doc["sensor"].as<const char*>()); // OKA deprecation warning with the message "Replace
as<char*>()withas<const char*>()" was added to allow a smooth transition.
DeserializationError::NotSupportedremovedOn a different topic,
DeserializationError::NotSupportedhas been removed. Instead of returning this error:
deserializeJson()leaves\uXXXXunchanged (only whenARDUINOJSON_DECODE_UNICODEis0)deserializeMsgPack()replaces unsupported values withnullsConst-aware
is<T>()Lastly, a very minor change concerns
JsonVariantConst::is<T>(). It used to returntrueforJsonArrayandJsonOject, but now it returnsfalse. Instead, you must useJsonArrayConstandJsonObjectConst.
How to install
There are several ways to install ArduinoJson, from simpler to more complex:
- Use the Arduino Library Manager or equivalent
- Download
ArduinoJson-v6.18.0.hput it in your project folder - Download
ArduinoJson-v6.18.0.zipand extract it into yourlibrariesfolder
Note: ArduinoJson-v6.18.0.h and ArduinoJson-v6.18.0.hpp are almost identical; the difference is that the .hpp keeps everything in the ArduinoJson namespace.