ArduinoJson

Features

Serialize and Deserialize

ArduinoJson supports both JSON serialization and deserialization.

Read JSON:

JsonObject& root = jsonBuffer.parseObject(myInput);

…modify:

root["last_modification"] = time();

…write back:

root.printTo(myOutput)

Fixed Memory Allocation

ArduinoJson uses a fixed memory allocation, allowing to work on devices with very little RAM.

You can choose to store data in the stack:

StaticJsonBuffer<512> jsonBuffer

…or on the heap

DynamicJsonBuffer jsonBuffer(512)

Intuitive Syntax

ArduinoJson has a simple and intuitive syntax to handle object and arrays.

JsonObject& root = jsonBuffer.parseObject(myJson);

const char* city = root["city"];
double temp = root["weather"]["temp"];

Implicit or Explict Casts

ArduinoJson supports two coding styles, with implicit or explicit casts

Implicit cast:

const char* city = root["city"];
float temp = root["temperature"];

Explicit cast:

auto city = root["city"].as<const char*>();
auto temp = root["temperature"].as<float>();

Parse From Stream

ArduinoJson is able to parse directly from an input Stream or std::istream

Parse input from the serial port:

JsonObject& root = jsonBuffer.parse(Serial);

…an Ethernet connection

JsonObject& root = jsonBuffer.parse(ethernetClient);

…or a Wifi connection

JsonObject& root = jsonBuffer.parse(wifiClient);

Compatible with Flash Strings

ArduinoJson works directly with strings stored in program memory (PROGMEM)

You can use a Flash String as JSON input

JsonObject& root = jsonBuffer.parseObject(F("{\"city\":\"Paris\",\"temp\":18.5}"));

…as a value

root["cond"] = F("Sunny");

…or as a key

float temp = root["temp"];

Print to Stream

ArduinoJson is able to print directly to a Print or std::ostream

// Send the JSON to the serial port
root.printTo(Serial);

…an Ethernet connection

root.printTo(ethernetClient);

…or a Wifi connection

root.printTo(wifiClient);

MIT License

ArduinoJson is open-source and uses one of the most permissive licenses so you can use it on any project.

✔️️ Commercial use

✔️️ Modification

✔️️ Distribution

✔️️ Private use

Header-only

ArduinoJson is a header-only library, meaning that all the code is the headers.

This greatly simplifies the compilation as you don’t have to worry about compiling and linking the library.

A single file distribution is also available; that way, you just need to download one header.

Continous fuzzing

Security is considered very seriously.

That is why ArduinoJson is integrated in Google’s OSS-Fuzz program.

As such, it is continuously fuzzed in search for security vunerabilities.

Fork me on GitHub