ArduinoJson
by Benoit Blanchon
ArduinoJson parses and generates JSON on memory-constrained microcontrollers, using a fixed-capacity in-memory document (as of v7, a self-resizing `JsonDocument` — earlier v6 required manually sizing a `StaticJsonDocument<N>`) instead of allocating freely like a desktop JSON library would. It's the standard way to build or parse the JSON payloads used by REST APIs, MQTT messages, and config files across ESP32/ESP8266 IoT projects. The catch that trips people up is the v6-to-v7 migration: v7's `JsonDocument` replaced v6's `StaticJsonDocument<N>`/`DynamicJsonDocument`, so capacity-sizing code and the `ARDUINOJSON_ASSISTANT` calculator from older tutorials no longer apply the same way — check which major version a tutorial targets before copying capacity-related code verbatim.
Installation
Arduino IDE — Library Manager
Sketch → Include Library → Manage Libraries → search ArduinoJson
PlatformIO
lib_deps = bblanchon/ArduinoJsonSupported boards
Examples
Build and serialize a JSON payload (v7 API)
Common pattern for building an MQTT or HTTP JSON payload from sensor readings.
#include <ArduinoJson.h>
JsonDocument doc;
doc["temp"] = 24.5;
doc["humidity"] = 60;
String output;
serializeJson(doc, output);
Serial.println(output);Parse an incoming JSON payload
Always check the DeserializationError before trusting parsed fields — malformed JSON fails silently otherwise.
JsonDocument doc;
DeserializationError error = deserializeJson(doc, jsonString);
if (!error) {
float temp = doc["temp"];
Serial.println(temp);
}