Quickstart
Serialization
JsonDocument doc;
doc["sensor"] = "gps";
doc["time"] = 1351824120;
doc["data"][0] = 48.756080;
doc["data"][1] = 2.302038;
serializeJson(doc, Serial);
// This prints:
// {"sensor":"gps","time":1351824120,"data":[48.756080,2.302038]}Deserialization
char json[] = "{\"sensor\":\"gps\",\"time\":1351824120,\"data\":[48.756080,2.302038]}";
JsonDocument doc;
deserializeJson(doc, json);
const char* sensor = doc["sensor"];
long time = doc["time"];
double latitude = doc["data"][0];
double longitude = doc["data"][1];Features
Intuitive Syntax
ArduinoJson has a simple and intuitive syntax to handle objects and arrays.
Fetch data:
const char* city = doc["city"];
double temp = doc["weather"]["temp"];
Set data:
doc["city"] = "Paris";
doc["weather"]["temp"] = 21.2;
Serialize and Deserialize
ArduinoJson supports both JSON serialization and deserialization.
Read JSON:
deserializeJson(doc, myInput);
…modify:
doc["last_modification"] = time();
…write back:
serializeJson(doc, myOutput);
Input filter
ArduinoJson can filter large inputs to keep only the fields that are relevant to your application, thereby saving a lot of memory.
JsonDocument filter;
filter["list"][0]["temperature"] = true;
deserializeJson(doc, input, DeserializationOption::Filter(filter));
Parse From Stream
ArduinoJson can parse directly from an input Stream or std::istream
Parse input from the serial port:
deserializeJson(doc, Serial);
…an Ethernet connection
deserializeJson(doc, ethernetClient);
…or a Wifi connection
deserializeJson(doc, wifiClient);
It also supports custom reader types.
Print to Stream
ArduinoJson is able to print directly to a Print or std::ostream
Send the JSON to the serial port:
serializeJson(doc, Serial);
…an Ethernet connection
serializeJson(doc, ethernetClient);
…or a Wifi connection
serializeJson(doc, wifiClient);
It also supports custom writer types.
Indented output
ArduinoJson can produce compact:
{"ports":[80,