arduino-libraries / Arduino_JSON

Official JSON Library for Arduino
GNU Lesser General Public License v2.1
151 stars 60 forks source link

How does this compare with ArduinoJson? #4

Closed bblanchon closed 4 years ago

bblanchon commented 4 years ago

Hi!

I'm the developer of ArduinoJson. I'm curious to know how this library differs from it. Why should someone choose this one over ArduinoJson?

Best Regards, Benoit

sandeepmistry commented 4 years ago

Hi @bblanchon,

The goal of this library is to be simple to use, and avoid C/C++ concepts that Arduino users are not familiar with.

bblanchon commented 4 years ago

Hi @sandeepmistry,

Thank you for your answer but it doesn't provide any comparison with ArduinoJson, nor any guidance to choose one or the other.

I made my own comparison and benchmark; you can read the article on arduinojson.org Here is a summary of the article:

Features

JSON support

ArduinoJson Arduino_JSON
JSON serialization ✔️ ✔️
JSON deserialization ✔️ ✔️
Decode UTF-16 literals ✔️ ✔️
Comments in JSON input ✔️
Single quotes in JSON input ✔️
Prettified output ✔️
Deserialization error information ✔️

Compatible types

ArduinoJson Arduino_JSON
Arduino String ✔️ ✔️
Flash strings ✔️ ✔️
Arduino streams ✔️
STL string ✔️
STL streams ✔️
long long ✔️

Integration with the C++ language

ArduinoJson Arduino_JSON
Access values with [] ✔️ ✔️
Implicit casts ✔️ ✔️
Namespace ✔️
const friendly ✔️
for friendly ✔️
template friendly ✔️
Deserialization error information ✔️
Usable outside of Arduino ✔️

Other features

ArduinoJson Arduino_JSON
Thread-safe ✔️ ✔️
MessagePack serialization ✔️
MessagePack deserialization ✔️
Stack-only allocation ✔️
Fixed heap allocation ✔️
Zero-copy ✔️

Project information

ArduinoJson Arduino_JSON
License MIT LGPL
Test coverage 98% 0%
Popularity 4055 21
Documentation ✔️

Performance

Serialize to Serial

ArduinoJson Arduino_JSON
Program size 3.6 KB ✔️ 7.9 KB
Running time 2.2 ms ✔️ 2.3 ms
Heap allocations 0 ✔️ 20
RAM usage 426 B ✔️ 454 B
Fragmentation 0 % ✔️ 1.5 %

Serialize to String

ArduinoJson Arduino_JSON
Program size 5.2 KB ✔️ 8.0 KB
Running time 2.1 ms 1.9 ms ✔️
Heap allocations 2 ✔️ 21
RAM usage 499 B ✔️ 534 B
Fragmentation 0 % ✔️ 6.21 %

Serialize to char[]

ArduinoJson Arduino_JSON
Program size 3.8 KB ✔️ 8.2 KB
Running time 1.7 ms ✔️ 1.9 ms
Heap allocations 0 ✔️ 21
RAM usage 492 B ✔️ 522 B
Fragmentation 0 % 0 %

Deserialize from const char*

ArduinoJson Arduino_JSON
Program size 4.0 KB ✔️ 11 KB
Running time 0.8 ms ✔️ 0.9 ms
Heap allocations 0 ✔️ 10
RAM usage 449 B ✔️ 540 B
Fragmentation 0 % 0%

Deserialize from char[]

ArduinoJson Arduino_JSON
Program size 4.1 KB ✔️ 11 KB
Running time 0.8 ms ✔️ 0.9 ms
Heap allocations 0 ✔️ 10
RAM usage 488 B ✔️ 540 B
Fragmentation 0 % 0%

Using a char[] enables the zero-copy mode of ArduinoJson, saving a large amount of memory.

Deserialize from Serial

ArduinoJson Arduino_JSON
Program size 4.2 KB ✔️ 11.3 KB
Running time 2.9 ms ✔️ 1004 ms
Heap allocations 0 ✔️ 73
RAM usage 387 B ✔️ 468 B
Fragmentation 0 % ✔️ 3.82 %

Conclusion

Best Regards, Benoit