ExplainerProgrammingTech/Web

ArduinoJSON – Efficient JSON serialization for embedded C++

What is ArduinoJson?

ArduinoJSON is decode JSON document and extract the information you want to display on the screen. So, it eats a JSON document and allows your program to extract the information you want.

Extracting information from a JSON document is what we call “deserialization.” Of course, ArduinoJson also knows how to perform the reverse operation, the “serialization,” which generates a JSON document. But that’s not all, ArduinoJson also supports the MessagePack format, an alternative to JSON that produces smaller documents.

Of course, ArduinoJson is not limited to weather stations. You can use ArduinoJson to simplify virtually any program that needs to connect to a web service (Twitter, Facebook, GitHub, etc). You can also use ArduinoJson to serialize configuration files, exchange information between boards…

ArduinoJson was created and is maintained by Benoît Blanchon, an experienced C++ developer who, like you, enjoys playing with electronics from time to time.

Benoît lives in France and has a Master’s degree from the Institut Supérieur d’Electronique de Paris. He works as software developer, but he developed ArduinoJson on his personal time.

Benoît created other successful open source software, the most famous being Winpooch which was a precursor to Windows Defender. He regularly writes in his blog “Good Code Smell”. He also created the websites meaningful.ly and Minymox.

ArduinoJson represents the best compromise between ease-of-use, efficiency, and portability.

It’s easy to use because you just need a few lines of code to do the work; there is very little ceremony compared to other libraries. Moreover, it leverages all C++ features to offer an elegant syntax to manipulate JSON documents.

It’s efficient because it’s designed to work on small microcontrollers, like the ones in Arduino boards. Indeed, you don’t program a microcontroller with 2KB of RAM the same way you program a PC with 32GB of RAM. Different problems require different solutions.

It’s portable because it works on any platform: Arduino, of course, but also on ESP8266, on ESP32… Yes! You can also use ArduinoJson on a PC, whether it’s Windows, macOS, or Linux. Does that sound silly after what you just read? On the contrary, being able to compile ArduinoJson on a PC allows running unit tests on your desktop machine before deploying to the microcontroller.

Why is ArduinoJson efficient ?

“Efficient” means it uses fewer resources to do the same work.

Those resources are:
  1. RAM
  2. CPU cycles
  3. Program Memory

ArduinoJson uses less RAM because it avoids copies when possible. Indeed, you don’t want the same information to be present several times in memory, that would be a terrible use of the RAM.

ArduinoJson uses fewer CPU cycles because it uses an optimized memory allocator. It can even work exclusively with stack memory, allowing to run on devices with very little memory.

ArduinoJson compiles to a small executable, leaving plenty of room for your program. Indeed, you’ll see that after including two or three libraries in your Arduino sketch, the program memory becomes very scarce.

How to install ArduinoJson.h ?

Option 1: Use the Arduino Library Manager

Recommendation

: Use this method if you use Arduino 1.6.x or newer.

Instructions:

  • Open the Arduino Library Manager
  • Search for “ArduinoJson”
  • Select the version: 5.13.5
  • Click install.

Option 2: Download the single header

Recommendation

: Use this method if you don’t use Arduino.

Instructions:

Option 3: Clone the repository

Recommendation

: Use this method if you want to make a Pull Request or use features that have not been released yet.

Instructions:

  • Run the command git clone https://github.com/bblanchon/ArduinoJson.git
  • Configure your compiler to add the folder ArduinoJson/src/ to the list of include folders (-I /path/to/ArduinoJson/src/ on GCC command line)

How to Use

Check out these Examples: JsonParser.ino, JsonGenerator.ino

Visit this : ESP8266 Parsing JSON

If you are not friendly with NodeMCU using Arduino IDE, Visit this: Arduino Support for ESP8266 with simple test code

Recommended: GPIO pins of ESP8266 and How to use efficiently

Recommended: NodeMCU ESP8266 OTA (Over-the-Air) using Arduino IDE


I hope you like this post “ArduinoJSON”. Do you have any questions? Leave a comment down below!

Thanks for reading. If you like this post probably you might like my next ones, so please support me by subscribing my blog.

We have other tutorials with ESP32 that you may find useful:

You may like also:

Harshvardhan Mishra

Hi, I'm Harshvardhan Mishra. Tech enthusiast and IT professional with a B.Tech in IT, PG Diploma in IoT from CDAC, and 6 years of industry experience. Founder of HVM Smart Solutions, blending technology for real-world solutions. As a passionate technical author, I simplify complex concepts for diverse audiences. Let's connect and explore the tech world together! If you want to help support me on my journey, consider sharing my articles, or Buy me a Coffee! Thank you for reading my blog! Happy learning! Linkedin

Leave a Reply

Your email address will not be published. Required fields are marked *