Bringing JSON to the Raspberry PI Pico and Pico-W

Bringing JSON to the Raspberry PI Pico and Pico-W

When I do machine-to-machine communication I normally use JSON as the format. The JSON libraries I use on the Raspberry PI Pico are by Rafa García, rafagafe on GitHub. JSON-Maker and Tiny-JSON

This blog post from DrJonEA.co.uk is part of an occasional series of blogs on C/C++ libraries for the Raspberry Pi Pico and Pico-W. 

JSON (JavaScript Object Notation) is a standard data interchange format that uses human-readable text to store and transmit data objects consisting of attribute–value pairs and arrays. It originated from the world of browser scripting. It is now very common in internet communication for structuring data.

I use JSON because the format is both machine and human-readable. It means I can quickly see if I have a problem or write test scripts that directly inject JSON. This makes testing and debugging easier and therefore speeds up my development.

I don’t always use the JSON-Maker library. Where I am only structuring a single attribute then I can do that easily in a “sprintf” statement. Where I am serialising more complex structures then JSON-Maker comes into it’s own. Saving me from having to think about all the edge cases with the data format.

For parsing JSON I always use the Tiny-JSON library. This gives a fully static memory based approach to parse JSON within the Pico. All the validation checks on data types are handled for me, and the result parsed into my attributes. Due to the nature of C/C++ this isn’t quite as seamless as parsing in JavaScript or Python but still huge value as a library.

I’ve used these two libraries on all my IoT projects from Saber Wall Light (https://youtu.be/Du-a5dGh3N4), cooling fan controller (https://youtu.be/js7NW6NMh4g)  and  my IoT course for the Pico-W on Udemy. I’ve also used it for simpler web service calls and passing data across the serial link between two Picos.

Though not specifically written for the Pico and Pico-W, these two libraries are well worth taking a little time to learn.

Leave a comment