2017-12-15 17:52:13 +01:00

2017-10-16 10:21:44 +02:00
2017-12-15 17:52:13 +01:00
---
2014-07-04 19:11:04 +02:00
2019-09-05 09:31:06 +02:00
[](https://www.ardu-badge.com/ArduinoJson/6.12.0)
2019-01-24 21:02:46 +01:00
[](https://ci.appveyor.com/project/bblanchon/arduinojson/branch/6.x)
[](https://travis-ci.org/bblanchon/ArduinoJson)
2019-09-19 09:28:35 +02:00
[](https://bugs.chromium.org/p/oss-fuzz/issues/list?sort=-opened& can=1& q=proj:arduinojson)
2019-01-24 21:02:46 +01:00
[](https://coveralls.io/github/bblanchon/ArduinoJson?branch=6.x)
2019-01-24 20:52:47 +01:00
[](https://github.com/bblanchon/ArduinoJson)
2014-07-04 19:11:04 +02:00
2017-12-15 17:52:13 +01:00
ArduinoJson is a C++ JSON library for Arduino and IoT (Internet Of Things).
2014-07-04 19:11:04 +02:00
2017-12-15 17:52:13 +01:00
## Features
2014-07-04 19:11:04 +02:00
2015-08-10 17:22:22 +02:00
* JSON decoding (comments are supported)
2014-11-11 14:26:57 +01:00
* JSON encoding (with optional indentation)
2018-06-04 17:48:10 +02:00
* MessagePack
2017-12-15 17:52:13 +01:00
* Elegant API, easy to use
2016-02-29 09:27:52 +01:00
* Fixed memory allocation (zero malloc)
* No data duplication (zero copy)
2017-12-15 17:52:13 +01:00
* Portable (written in C++98, can be used in any C++ project)
2015-05-23 15:32:50 +02:00
* Self-contained (no external dependency)
2014-07-04 19:11:04 +02:00
* Small footprint
2017-12-15 17:52:13 +01:00
* Input and output streams
* [100% code coverage ](https://coveralls.io/github/bblanchon/ArduinoJson )
* [Header-only library ](https://en.wikipedia.org/wiki/Header-only )
* [MIT License ](https://en.wikipedia.org/wiki/MIT_License )
2018-01-15 10:22:04 +01:00
* [Comprehensive documentation ](https://arduinojson.org?utm_source=github&utm_medium=readme )
2014-07-04 19:11:04 +02:00
2017-12-15 17:52:13 +01:00
## Compatibility
ArduinoJson works on the following hardware:
* < img src = "https://www.arduino.cc/favicon.ico" height = "16" width = "16" > Arduino boards: [Uno ](https://www.arduino.cc/en/Main/ArduinoBoardUno ), [Due ](https://www.arduino.cc/en/Main/ArduinoBoardDue ), [Mini ](https://www.arduino.cc/en/Main/ArduinoBoardMini ), [Micro ](https://www.arduino.cc/en/Main/ArduinoBoardMicro ), [Yun ](https://www.arduino.cc/en/Main/ArduinoBoardYun )...
* < img src = "http://espressif.com/sites/all/themes/espressif/favicon.ico" height = "16" width = "16" > Espressif chips: [ESP8266 ](https://en.wikipedia.org/wiki/ESP8266 ), [ESP32 ](https://en.wikipedia.org/wiki/ESP32 )
* < img src = "https://www.wemos.cc/themes/martin-materialize-parallax/assets/favicon.ico" height = "16" width = "16" > WeMos boards: [D1 ](https://wiki.wemos.cc/products:d1:d1 ), [D1 mini ](https://wiki.wemos.cc/products:d1:d1_mini ), ...
* < img src = "http://redbearlab.com/favicon.ico" height = "16" width = "16" > RedBearLab boards: [BLE Nano ](http://redbearlab.com/blenano/ ), [BLE Mini ](http://redbearlab.com/blemini/ ), [WiFi Micro ](https://redbear.cc/product/wifi/wifi-micro.html ), [LOLIN32 ](https://wiki.wemos.cc/products:lolin32:lolin32 )...
* < img src = "https://www.pjrc.com/favicon.ico" height = "16" width = "16" > [Teensy ](https://www.pjrc.com/teensy/ ) boards
* < img src = "https://software.intel.com/sites/all/themes/zero/favicon.ico" height = "16" width = "16" > Intel boards: Edison, Galileo...
* < img src = "https://www-assets.particle.io/images/favicon.png" height = "16" width = "16" > Particle boards: [Photon ](https://www.particle.io/products/hardware/photon-wifi-dev-kit ), [Electron ](https://www.particle.io/products/hardware/electron-cellular-dev-kit )...
* < img src = "http://www.ti.com/favicon.ico" height = "16" width = "16" > Texas Instruments boards: [MSP430 ](http://www.ti.com/microcontrollers/msp430-ultra-low-power-mcus/overview/overview.html )...
ArduinoJson compiles with zero warning on the following compilers, IDEs, and platforms:
2015-09-29 21:49:19 +02:00
2017-12-15 17:52:13 +01:00
* < img src = "https://www.arduino.cc/favicon.ico" height = "16" width = "16" > [Arduino IDE ](https://www.arduino.cc/en/Main/Software )
* < img src = "http://cdn.platformio.org/favicon.ico" height = "16" width = "16" > [PlatformIO ](http://platformio.org/ )
* < img src = "http://energia.nu/img/favicon.ico" height = "16" width = "16" > [Energia ](http://energia.nu/ )
* < img src = "http://www.visualmicro.com/pics/arduino-visual-studio-ld.png" height = "16" width = "16" > [Visual Micro ](http://www.visualmicro.com/ )
* < img src = "http://www.atmel.com/Images/favicon.ico" height = "16" width = "16" > [Atmel Studio ](http://www.atmel.com/microsite/atmel-studio/ )
* < img src = "https://www.iar.com/favicon.ico" height = "16" width = "16" > [IAR Embedded Workbench ](https://www.iar.com/iar-embedded-workbench/ )
* < img src = "http://www.st.com/etc/clientlibs/st-site/media/app/images/favicon.png" height = "16" width = "16" > [Atollic TrueSTUDIO ](https://atollic.com/truestudio/ )
* < img src = "http://www.keil.com/favicon.ico" height = "16" width = "16" > [Keil uVision ](http://www.keil.com/ )
* < img src = "http://www.microchip.com/favicon.ico" height = "16" width = "16" > [MPLAB X IDE ](http://www.microchip.com/mplab/mplab-x-ide )
* < img src = "https://gcc.gnu.org/favicon.ico" height = "16" width = "16" > [GCC ](https://gcc.gnu.org/ )
* < img src = "https://clang.llvm.org/favicon.ico" height = "16" width = "16" > [Clang ](https://clang.llvm.org/ )
* < img src = "https://www.visualstudio.com/favicon.ico" height = "16" width = "16" > [Visual Studio ](https://www.visualstudio.com/ )
2015-09-29 21:49:19 +02:00
2017-12-15 17:52:13 +01:00
## Quickstart
2014-07-04 19:11:04 +02:00
2017-12-15 17:52:13 +01:00
### Deserialization
Here is a program that parses a JSON document with ArduinoJson.
2015-08-24 18:10:10 +02:00
2015-10-30 22:29:47 +01:00
```c++
char json[] = "{\"sensor\":\"gps\",\"time\":1351824120,\"data\":[48.756080,2.302038]}";
2014-07-04 19:11:04 +02:00
2019-01-14 10:32:19 +01:00
DynamicJsonDocument doc(1024);
2018-04-17 21:27:45 +02:00
deserializeJson(doc, json);
2014-07-05 12:53:34 +02:00
2019-03-24 18:21:58 +01:00
const char* sensor = doc["sensor"];
long time = doc["time"];
double latitude = doc["data"][0];
double longitude = doc["data"][1];
2015-10-30 22:29:47 +01:00
```
2014-07-05 12:53:34 +02:00
2018-01-15 10:22:04 +01:00
See the [tutorial on arduinojson.org ](https://arduinojson.org/doc/decoding/?utm_source=github&utm_medium=readme )
2017-01-03 22:03:50 +01:00
2017-12-15 17:52:13 +01:00
### Serialization
2017-05-27 15:31:47 +02:00
2017-12-15 17:52:13 +01:00
Here is a program that generates a JSON document with ArduinoJson:
2015-08-24 18:10:10 +02:00
2015-10-30 22:29:47 +01:00
```c++
2019-01-14 10:32:19 +01:00
DynamicJsonDocument doc(1024);
2018-04-17 21:27:45 +02:00
2019-03-24 18:21:58 +01:00
doc["sensor"] = "gps";
doc["time"] = 1351824120;
2014-07-05 12:53:34 +02:00
2019-03-24 18:21:58 +01:00
JsonArray data = doc.createNestedArray("data");
2017-05-20 09:06:53 +02:00
data.add(48.756080);
data.add(2.302038);
2014-07-05 12:53:34 +02:00
2018-04-17 21:27:45 +02:00
serializeJson(doc, Serial);
2015-10-30 22:29:47 +01:00
// This prints:
// {"sensor":"gps","time":1351824120,"data":[48.756080,2.302038]}
2015-10-30 23:03:16 +01:00
```
2014-07-05 12:53:34 +02:00
2018-01-15 10:22:04 +01:00
See the [tutorial on arduinojson.org ](https://arduinojson.org/doc/encoding/?utm_source=github&utm_medium=readme )
2015-11-09 22:55:29 +01:00
2017-12-15 17:52:13 +01:00
## Documentation
2015-11-09 22:55:29 +01:00
2018-01-15 10:22:04 +01:00
The documentation is available on [arduinojson.org ](https://arduinojson.org/?utm_source=github&utm_medium=readme ), here are some shortcuts:
2017-06-22 21:56:41 +02:00
2018-01-15 10:22:04 +01:00
* The [Examples ](https://arduinojson.org/example/?utm_source=github&utm_medium=readme ) show how to use the library in various situations.
* The [API Reference ](https://arduinojson.org/api/?utm_source=github&utm_medium=readme ) contains the description of each class and function.
* The [FAQ ](https://arduinojson.org/faq/?utm_source=github&utm_medium=readme ) has the answer to virtually every question.
* The [ArduinoJson Assistant ](https://arduinojson.org/assistant/?utm_source=github&utm_medium=readme ) writes programs for you!
2015-11-09 22:55:29 +01:00
2014-11-11 17:50:40 +01:00
---
2014-07-05 16:09:37 +02:00
2018-01-05 09:17:24 +01:00
Do you like this library? Please [star this project on GitHub ](https://github.com/bblanchon/ArduinoJson/stargazers )!
What? You don't like it but you *love* it?
2018-02-26 16:05:16 +01:00
We don't take donations anymore, but [we sell a book ](https://arduinojson.org/book/?utm_source=github&utm_medium=readme ), so you can help and learn at the same time!