<commit_before>Arduino JSON library
====================

*An elegant and efficient JSON library for embedded systems.*

It's design to have the most intuitive API, the smallest footprint and works without any allocation on the heap (no malloc).

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.

Features
--------

* JSON decoding: [see documentation here](/JsonParser/)
* JSON encoding: [see documentation here](/JsonGenerator/)
* Elegant API, very easy to use 
* Fixed memory allocation (no malloc)
* Small footprint
* MIT License

Feature comparison
------------------

| Library      | Memory allocation | Nested objects | Parser size | Encoder size  |
| ------------ | ----------------- | -------------- | ----------- | ------------- |
| Arduino JSON | static            | yes            | 2760 Bytes  | 862 bytes     |
| json-arduino | dynamic           | no             | 3348 (+21%) | not supported |
| aJson        | dynamic           | yes            | 5088 (+84%) | 4678 (+540%)  |

"Parser size" was measured with a program parsing `{"sensor":"outdoor","value":25.6}`.
For each library, I wrote a program that extracts a string and a float. I subtracted the size of a program doing the same without any JSON parsing involved. [Source files are here](https://gist.github.com/bblanchon/e8ba914a7109f3642c0f).

"Encoder size" was measured with a program generating `{"sensor":"outdoor","value":25.6}`.
[Source files are here](https://gist.github.com/bblanchon/60224e9dcfeab4ddc7e9).

In each case the target platform was an Arduino Duemilanove and Arduino IDE 1.0.5 was used. 

Links: [json-arduino](https://github.com/not404/json-arduino), [aJson](https://github.com/interactive-matter/aJson) 

Testimonials
------------

From Arduino's Forum user `jflaplante`:
> I tried the  [aJson and json-arduino] before trying your library. I always ran into memory problem after a while. 
> I have no such problem so far with your library. It is working perfectly with my web services.

From Arduino's Forum user `gbathree`:
> 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.

From StackOverflow user `thegreendroid`:
> 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.

Related blog posts
-----

* [The project I originally wrote this library for](http://blog.benoitblanchon.fr/rfid-payment-terminal/)
* [Motivation for this library](http://blog.benoitblanchon.fr/arduino-json-parser/)
* [Release of version 2](http://blog.benoitblanchon.fr/arduino-json-v2-0/)
* [Release of version 3](http://blog.benoitblanchon.fr/arduino-json-v3-0/)<commit_msg>Updated for v4.0<commit_after>Arduino JSON library
====================

*An elegant and efficient JSON library for embedded systems.*

It's design to have the most intuitive API, the smallest footprint and works without any allocation on the heap (no malloc).

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.

Features
--------

* JSON decoding
* JSON encoding (with optional indentation)
* Elegant API, very easy to use 
* Fixed memory allocation (no malloc)
* Small footprint
* MIT License

Quick start
-----------

#### Decoding / Parsing
   
    char json[] = "{\"sensor\":\"gps\",\"time\":1351824120,\"data\":[48.756080,2.302038]}";

    StaticJsonBuffer<200> jsonBuffer;

    JsonObject& root = jsonBuffer.parseObject(json);

    const char* sensor = root["sensor"];
    long time          = root["time"];
    double latitude    = root["data"][0];
    double longitude   = root["data"][1];

[See complete guide](/doc/Decoding JSON.md)

#### Encoding / Generating
   
    StaticJsonBuffer<200> jsonBuffer;

    JsonObject& root = jsonBuffer.createObject();
    root["sensor"] = "gps";
    root["time"] = 1351824120;

    JsonArray& data = root.createNestedArray("data");
    data.add(48.756080, 6);  // 6 is the number of decimals to print
    data.add(2.302038, 6);   // if not specified, 2 digits are printed

    root.printTo(Serial);
    // This prints:
    // {"sensor":"gps","time":1351824120,"data":[48.756080,2.302038]}

[See complete guide](/doc/Encoding JSON.md)

Testimonials
------------

From Arduino's Forum user `jflaplante`:
> I tried the  [aJson and json-arduino] before trying your library. I always ran into memory problem after a while. 
> I have no such problem so far with your library. It is working perfectly with my web services.

From Arduino's Forum user `gbathree`:
> 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.

From StackOverflow user `thegreendroid`:
> 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.
{'fraction_non_alphanumeric': 0.13207179087007412, 'fraction_numerical': 0.030238002341006633, 'mean_word_length': 3.3192923336141535, 'pattern_counts': {'":': 10, '<': 5, '<?xml version=': 0, '>': 13, 'https://': 4, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5573799', 'n_tokens_mistral': 1614, 'n_tokens_neox': 1451, 'n_words': 588}