Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Breaking Changes in ArduinoJson 6.0

DZone's Guide to

Breaking Changes in ArduinoJson 6.0

Having trouble with your ArduinoJson version 6.0? Click here to learn more about this problem and how to fix it!

· IoT Zone ·
Free Resource


Hey Folks,

Got a quick update for you. If you are handling JSON with any Arduino related project and are using the library ArduinoJson to make your life easier, you may run into a problem with tutorials written previously to now (including some of ours) where your code wouldn't compile with errors related to the declaration of jsonBuffer.

Don't worry, we have the solution for you.

ArduinoJson version 6.0 was recently released, and it included a breaking change which is most likely the cause to JSON related problems.

In the latest version, the concept of JsonBuffer has been replaced with the concept of JsonDocument.

Previously, you could create a JSON object like this:

StaticJsonBuffer<512> jsonBuffer;
JsonObject& root = jsonBuffer.createObject();


With the new changes, here's how you would achieve the same thing:

StaticJsonDocument<512> jsonBuffer;
JsonObject& root = jsonBuffer.to<JsonObject>();


In the previous version of ArduinoJson, you would use the printTo() method to serialize json into a string, eg:

data.printTo(dataStr);


Now, you'll need to use the new serializeJson function:

serializeJson(data, dataStr);


For more information about other changes in ArduinoJson 6.0, check out this article.

Topics:
json ,arduino ,updates ,iot ,arduinojson 6.0

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}