DEV Community

Austin Spivey for Wia

Posted on

3 1

Breaking Changes in ArduinoJson 6.0

We have a quick update for you if you are handling JSON with any Arduino related project.

If you are using the library ArduinoJson to make your life easier, you may run into a problem with tutorials written prior to now (Including some of ours), where your code doesn't compile with errors related to the declaration of the 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 wpuld 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.

API Trace View

How I Cut 22.3 Seconds Off an API Call with Sentry

Struggling with slow API calls? Dan Mindru walks through how he used Sentry's new Trace View feature to shave off 22.3 seconds from an API call.

Get a practical walkthrough of how to identify bottlenecks, split tasks into multiple parallel tasks, identify slow AI model calls, and more.

Read more →

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay