Source: https://mokxi.com/libraries/arduinojson
Updated: 2026-11-02

Libraries / Data and time
Arduino library · Data and time

# ArduinoJson: read and write JSON on an Arduino or ESP32

ArduinoJson, by Benoît Blanchon, is the standard way to handle JSON on a microcontroller: parse an API’s reply into values you can index like doc["main"]["temp"], or build an object and print it to Serial, a web page or an MQTT message. It works the same on an Uno as on an ESP32, though the Uno’s 2 KB of RAM limits how big a document can be.

Open the example in the editor See the calls

Built in on Mokxi: #include <ArduinoJson.h> and it builds, with nothing to install. Free, and no account needed.

## What ArduinoJson does

Version 7 has one type, JsonDocument, which grows as needed. Version 6, which many tutorials still show, made you choose StaticJsonDocument<200> or DynamicJsonDocument(1024) with a fixed capacity, and createNestedArray() instead of doc["data"].to<JsonArray>(). Code written for one version mostly compiles on the other, but the capacity numbers in 6.x examples are what cause "NoMemory" when an input grows.

Reading is deserializeJson(doc, input), where input can be a char array, a String, Serial, a WiFiClient or a File, and it returns a DeserializationError you should test before using anything in the document.

Library Manager name | ArduinoJson

Author | Benoit Blanchon

Include | #include <ArduinoJson.h>

Boards | every board Mokxi compiles for but ATtiny85

In the simulator | Simulated: it runs against the part the way it does on the bench.

## Install it

It builds on every board Mokxi compiles for but ATtiny85.

In Mokxi it is built in: #include <ArduinoJson.h> and the sketch compiles, with no download, no zip and no Library Manager.

On a real board, install "ArduinoJson" by Benoit Blanchon from the Arduino IDE’s Library Manager (Sketch, Include Library, Manage Libraries), or add ArduinoJson to lib_deps in PlatformIO. Mokxi follows the calls of release 7.3.0, so a sketch written here builds there too.

What to know in the simulator: Integers are 32 bits. A document’s capacity is not enforced: it takes what the heap gives. A filtered read keeps what the filter names once the whole input is read, rather than skipping the rest as it goes.

ESP32-C3 · Arduino Uno · Arduino Nano · Arduino Mega 2560 · Arduino Leonardo · SparkFun Pro Micro · Arduino Micro · ESP32-C6 · Raspberry Pi Pico · Raspberry Pi Pico W · Seeed XIAO SAMD21 · STM32 · STM32 Nucleo-F411RE · STM32 Blue Pill · micro:bit V2 · Arduino Uno R4 · ESP32 DevKit · ESP32-S3-DevKitC-1 · ESP8266 NodeMCU · Arduino Pro Mini 3.3 V · Seeed XIAO ESP32-C3 · ESP32-C3 SuperMini · Seeed XIAO ESP32-C6 · ESP32-DevKitC V4 · LOLIN32 Lite · Wemos D1 R32 · Cheap Yellow Display · TTGO T-Display · Seeed XIAO ESP32-S3 · Arduino Nano ESP32 · Arduino Nano RP2040 Connect · Seeed XIAO RP2040 · Waveshare RP2040-Zero · Arduino Uno R4 WiFi

## The calls you will use

In the order a sketch meets them.

### JsonDocument doc

A document that holds a whole JSON tree. In 6.x write StaticJsonDocument<256> doc; with a capacity in bytes.

### DeserializationError error = deserializeJson(doc, json)

Parses JSON text into the document. error is false on success; error.c_str() gives the reason, such as InvalidInput or NoMemory.

### float temp = doc["main"]["temp"]

Reads a value by key and index. The assignment converts it; a missing key gives 0 or a null pointer instead of crashing.

### doc["sensor"] = "gps"

Adds or replaces a member. Numbers, booleans, strings and nested objects all work.

### JsonArray data = doc["data"].to<JsonArray>()

Creates a nested array; data.add(48.75) appends to it. createNestedArray("data") is the 6.x spelling.

### serializeJson(doc, Serial)

Writes the document as compact JSON to any Print: Serial, a String, a client or a file. serializeJsonPretty() adds line breaks and indents.

### measureJson(doc)

The length the serialized JSON will have, for a Content-Length header or a buffer size.

### doc.containsKey("error")

True when the member exists, which tells "missing" apart from a value that happens to be 0.

## Example: Write and read JSON

On the Arduino Uno R3. It runs in the browser exactly as printed.

sketch.ino · Arduino Uno R3

Open it in the editor, wired and ready to run

## Common errors and how to fix them

### deserializeJson() failed: NoMemory

In 6.x the document’s capacity is too small for the input: raise the number in StaticJsonDocument<N>, or use the ArduinoJson Assistant to size it. In 7.x it means the heap is full, so filter the input or use a board with more RAM.

### deserializeJson() failed: InvalidInput

What you passed is not JSON: often an HTTP error page, a reply cut short, or bytes left over from a previous read. Print the input first and check the status code before parsing.

### A string read from the document turns into garbage later

A const char* taken from doc["name"] points into the document, so it is only valid while the document lives and is not cleared. Copy it into a String or a char array if you need it after that.

## Questions and answers

### ArduinoJson or Arduino_JSON?

ArduinoJson is faster, smaller and documented in depth, and most libraries that take JSON expect it. Arduino_JSON feels like JavaScript (JSONVar, JSON.parse) and suits short ESP32 web examples. Do not mix them in one sketch.

## Keep going

### Learn

- ESP32 HTTP GET Request: Fetch the Weather as JSON

### More data and time libraries

- QRCode
- Madgwick
- PID
- TimerOne
- MsTimer2
- Low-Power
- RTClib
- DS1307RTC

Every built-in library · Open the editor

## Try ArduinoJson without installing anything

Open the example, change the sketch, and keep your version in a free account.

Start building free

Open the editor
