1 | Arduino JSON library
|
---|
2 | ====================
|
---|
3 |
|
---|
4 | [![Build status](https://ci.appveyor.com/api/projects/status/m7s53wav1l0abssg/branch/master?svg=true)](https://ci.appveyor.com/project/bblanchon/arduinojson/branch/master) [![Build Status](https://travis-ci.org/bblanchon/ArduinoJson.svg?branch=master)](https://travis-ci.org/bblanchon/ArduinoJson) [![Coverage Status](https://img.shields.io/coveralls/bblanchon/ArduinoJson.svg)](https://coveralls.io/r/bblanchon/ArduinoJson?branch=master) [![Star this project](http://githubbadges.com/star.svg?user=bblanchon&repo=ArduinoJson&style=flat&color=fff&background=007ec6)](https://github.com/bblanchon/ArduinoJson)
|
---|
5 |
|
---|
6 | *An elegant and efficient JSON library for embedded systems.*
|
---|
7 |
|
---|
8 | It's designed to have the most intuitive API, the smallest footprint and works without any allocation on the heap (no malloc).
|
---|
9 |
|
---|
10 | It has been written with Arduino in mind, but it isn't linked to Arduino libraries so you can use this library in any other C++ project.
|
---|
11 |
|
---|
12 | Features
|
---|
13 | --------
|
---|
14 |
|
---|
15 | * JSON decoding (comments are supported)
|
---|
16 | * JSON encoding (with optional indentation)
|
---|
17 | * Elegant API, very easy to use
|
---|
18 | * Fixed memory allocation (zero malloc)
|
---|
19 | * No data duplication (zero copy)
|
---|
20 | * Portable (written in C++98)
|
---|
21 | * Self-contained (no external dependency)
|
---|
22 | * Small footprint
|
---|
23 | * MIT License
|
---|
24 |
|
---|
25 | Works on
|
---|
26 | --------
|
---|
27 |
|
---|
28 | * All Arduino boards (Uno, Due, Mini, Micro, Yun...)
|
---|
29 | * ESP8266
|
---|
30 | * Teensy
|
---|
31 | * Intel Edison
|
---|
32 | * PlatformIO
|
---|
33 | * Energia
|
---|
34 | * RedBearLab boards (BLE Nano...)
|
---|
35 | * Computers (Windows, Linux, OSX...)
|
---|
36 |
|
---|
37 | See [FAQ: Compatibility issues](https://github.com/bblanchon/ArduinoJson/wiki/Compatibility-issues)
|
---|
38 |
|
---|
39 | Quick start
|
---|
40 | -----------
|
---|
41 |
|
---|
42 | #### Decoding / Parsing
|
---|
43 |
|
---|
44 | ```c++
|
---|
45 | char json[] = "{\"sensor\":\"gps\",\"time\":1351824120,\"data\":[48.756080,2.302038]}";
|
---|
46 |
|
---|
47 | StaticJsonBuffer<200> jsonBuffer;
|
---|
48 |
|
---|
49 | JsonObject& root = jsonBuffer.parseObject(json);
|
---|
50 |
|
---|
51 | const char* sensor = root["sensor"];
|
---|
52 | long time = root["time"];
|
---|
53 | double latitude = root["data"][0];
|
---|
54 | double longitude = root["data"][1];
|
---|
55 | ```
|
---|
56 |
|
---|
57 | #### Encoding / Generating
|
---|
58 |
|
---|
59 | ```c++
|
---|
60 | StaticJsonBuffer<200> jsonBuffer;
|
---|
61 |
|
---|
62 | JsonObject& root = jsonBuffer.createObject();
|
---|
63 | root["sensor"] = "gps";
|
---|
64 | root["time"] = 1351824120;
|
---|
65 |
|
---|
66 | JsonArray& data = root.createNestedArray("data");
|
---|
67 | data.add(48.756080, 6); // 6 is the number of decimals to print
|
---|
68 | data.add(2.302038, 6); // if not specified, 2 digits are printed
|
---|
69 |
|
---|
70 | root.printTo(Serial);
|
---|
71 | // This prints:
|
---|
72 | // {"sensor":"gps","time":1351824120,"data":[48.756080,2.302038]}
|
---|
73 | ```
|
---|
74 |
|
---|
75 |
|
---|
76 | Documentation
|
---|
77 | -------------
|
---|
78 |
|
---|
79 | The documentation is available online in the [Arduino JSON wiki](https://github.com/bblanchon/ArduinoJson/wiki)
|
---|
80 |
|
---|
81 | Testimonials
|
---|
82 | ------------
|
---|
83 |
|
---|
84 | From Arduino's Forum user `jflaplante`:
|
---|
85 | > I tried aJson json-arduino before trying your library. I always ran into memory problem after a while.
|
---|
86 | > I have no such problem so far with your library. It is working perfectly with my web services.
|
---|
87 |
|
---|
88 | From Arduino's Forum user `gbathree`:
|
---|
89 | > Thanks so much - this is an awesome library! If you want to see what we're doing with it - the project is located at www.photosynq.org.
|
---|
90 |
|
---|
91 | From StackOverflow user `thegreendroid`:
|
---|
92 | > It has a really elegant, simple API and it works like a charm on embedded and Windows/Linux platforms. We recently started using this on an embedded project and I can vouch for its quality.
|
---|
93 |
|
---|
94 | From GitHub user `zacsketches`:
|
---|
95 |
|
---|
96 | > Thanks for a great library!!!
|
---|
97 | > I've been watching you consistently develop this library over the past six months, and I used it today for a publish and subscribe architecture designed to help hobbyists move into more advanced robotics. Your library allowed me to implement remote subscription in order to facilitate multi-processor robots.
|
---|
98 | > ArduinoJson saved me a week's worth of time!!
|
---|
99 |
|
---|
100 | [From Reddit user `erm_what_`](https://www.reddit.com/r/arduino/comments/3jj6ep/announcing_arduinojson_50/cusjk8c):
|
---|
101 |
|
---|
102 | > This is a great library and I wouldn't be able to do the project I'm doing without it. I completely recommend it.
|
---|
103 |
|
---|
104 | [From Reddit user `makerhacks`](https://www.reddit.com/r/arduino/comments/3jj6ep/announcing_arduinojson_50/cusqg7b):
|
---|
105 |
|
---|
106 | > I am just starting an ESP8266 clock project and now I can output JSON from my server script and interpret it painlessly.
|
---|
107 |
|
---|
108 | Donators
|
---|
109 | --------
|
---|
110 |
|
---|
111 | Special thanks to the following persons and companies who made generous donations to the library author:
|
---|
112 |
|
---|
113 | * Robert Murphy
|
---|
114 | * Surge Communications
|
---|
115 | * Alex Scott
|
---|
116 | * Firepick Services LLC
|
---|
117 | * A B Doodkorte
|
---|
118 | * Scott Smith
|
---|
119 | * Johann Stieger
|
---|
120 | * Gustavo Donizeti Gini
|
---|
121 |
|
---|
122 | ---
|
---|
123 |
|
---|
124 | Found this library useful? Please star this project or [help me back with a donation!](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=donate%40benoitblanchon%2efr&lc=GB&item_name=Benoit%20Blanchon&item_number=Arduino%20JSON¤cy_code=EUR&bn=PP%2dDonationsBF%3abtn_donate_LG%2egif%3aNonHosted) :smile:
|
---|