Go Down

Topic: JSON Library? (Read 24451 times) previous topic - next topic


Hi all,

Given the recent changes in the twitter APIs - they have deprecated their 1.0 API which offered REST and now they're enforcing 1.1 which has only support for JSON - I'm looking for a decent and functionning JSON Library for Arduino. I've read about a quite old project called aJSON but it seems to be dead since 2010 and there's no download available: the github account linked from the article is empty.

Do you guys have a recommendation for me?

Thanks in advance!


It's a start : https://github.com/not404/json-arduino
Met vriendelijke groet / kindest regards
Nico Verduin
Do not PM me for personal consultancy unless you are willing to pay for it.


There is a json lib here that my colleage wrote for chipKIT (Microchip PIC32 Arduino Compatible boards).  It may work with Arduino.  At its core it makes calls to Arduino libs used in chipKIT.  I believe it does make use of malloc, which from my understanding does not work so great on Arduino.  Its maintained and used heavily but not documented.




I don't know if this is something you still need, but aJson seems to be available on Github.
See the project homepage here: http://interactive-matter.eu/how-to/ajson-arduino-json-library/



For some reasons, the Github link from the page I've linked before gives an empty repository.
You can find the aJson library here:



I was not satisfied with "aJson" and "json-arduino" because both of them rely on malloc() and therefore doesn't perform well in very low memory conditions.

So I wrote my own "malloc-free JSON parser":


i try your library but the parsing not extract the name the age etc etc.


i try your library but the parsing not extract the name the age etc etc.

Fail. You're going to have to do much better than that. It doesn't extract what information from what? Be very specific!
The art of getting good answers lies in asking good questions.


Hey BenoitB - thanks for making that library!

I've tried running the example in the jsonparser library on a Teensy 3.0 and Teensy 3.1, however, and can't get the ParseAnObject() subroutine to complete successfully (this calls the hashTable.getString, hashTable.getArray... or other hashTable commands).  The array.getArray command works fine, and the ParseAnArray() subroutine runs fine.  I have managed to get ParseAnObject() subroutine to successfully complete on an Arduino Uno and Teensy 2.0, however, so it must be some compatability issue with 3.0 and 3.1 (ARM perhaps??). 

There's no compile errors, but the program simply stops at line 25 when it runs .getString for the first time. 

Code: [Select]
char* name = hashTable.getString("Name");

So, to be clear and perhaps too obvious, the output looks like this:

Parse {"Name":"Blanchon","Skills":["C","C++","C#"],"Age":32,"Online":true}

I tried commenting out getString and attempting the getArray and getLong and they also do not work.  I also tried explicitely adding the following libraries to the top of the file...

Code: [Select]
#include <JsonParser.h>
#include "utility/jsmn.h"
#include <stdlib.h> // for strtol, strtod
#include <string.h> // for strcmp()
#include "JsonObjectBase.h"
#include "JsonHashTable.h"
#include "JsonArray.h"

seems silly but I've had previous examples (Adafruit's sensor library) not compile without explicitely adding the AdafruitSensor.h library to the top of my .ino file (even though it was referenced in the library .h file...).  Anyway, that didn't work either.

Any ideas?



I was not satisfied with "aJson" and "json-arduino" because both of them rely on malloc() and therefore doesn't perform well in very low memory conditions.

So I wrote my own "malloc-free JSON parser":

I tried the first two 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.

Thanks Benoit for a very well polished product!



Feb 25, 2014, 07:21 pm Last Edit: Feb 26, 2014, 03:08 pm by gbathree Reason: 1
I'm having an issue pulling all of the tokens from a JSON - I can get some of them, but not others.  I'm using a Teensy 3.1 with 64K SRAM.

Here's two JSONs I've tested.  In both case, the last few tokens are not parsed.  Thinking it was a problem with the length of the JSON, I tried the 2nd JSON which is <32 tokens, so it's fairly small but still has the same issue:

-- does not parse measlights, measlights2, altc, and altd
Code: [Select]


-- does not parse altc and altd
Code: [Select]


I can't seem to get those last few values to be parsed correctly.  And it's always the last few values - if you switch the order of the tokens, it's always the ones at the end which aren't parsed.  It makes me think it's a memory issue, but I know that's not the case, the program is small and there's plenty of memory left.  I've messed around with lots of things, like changing the JsonParser size, changing the varaible names, moving them around within the JSON itself, calling the values in a different way... but haven't been able to figure it out.

Any suggestions, ideas, or similar problems?

See attached for the code I used to test.  Just enter any number followed by the JSON in the serial com window to parse (one of the above 2).  It tries to find the variables it's looking for, it prints their values if they are found.  


Hi gbathree,

Sorry for making you wait so long.

About your first post.
There was a mistake in the sample code.
You need to replace char* json by char json[].
It was generating an access violation because the memory was write protected and the parser needs to alter the string.
I didn't see that on Arduino because there is no memory protection.

About your second post.
You are right: there was a bug in the parser's code.
The bug occurred as soon as the JSON string contains a multi-dimensional array.
I fixed it in the master branch, you can download it at:

Please keep me informed.



Confirmed - works great now!  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.



Hi, this other library goes one step beyond than bblanchon one. Apart form not doing mallocs it does not need to have the whole json string in memory, it receives a Stream and reads it char by char because sometime just the json string is too big. It is called StreamJsonReader. Here's a blog post about the motivation and a little example  


ArduinoJsonParser looks like a great library BenoitB, well done.

Something I have noticed that I cant seem to get fixed. This library doesn't seem to parse tiered objects that are not array types. I am trying to parse something like the following;

Code: [Select]

I can successfully extract the "method" key, and can validate the "params" key with

Code: [Select]

I have tried to extract the params hashTable with

Code: [Select]
JsonHashTable paramsTable = hashTable.getHashTable("params");

but that also seems to fail. Am I missing something, or is this a fault?


Go Up