ArduinoJson: F.A.Q

Why does my device crash or reboot?

99.999% of the time, this is caused by a “stack overflow”, i.e. you have too many variables in the “stack”.

Before reading further, make sure that your target platform does have enough RAM to store the JsonBuffer and possibly the JSON input too:

Once you’re sure that your device has enough RAM, you should move the JsonBuffer to the heap. Just replace your StaticJsonBuffer by a DynamicJsonBuffer.

If your JSON input is stored in the stack, you should move it to the heap too.

For instance, if you have a program like this:

char content[MAX_CONTENT_SIZE];
StaticJsonBuffer<JSON_BUFFER_SIZE> jsonBuffer;

receive(content);
JsonObject& root = jsonBuffer.parseObject(content);

Serial.println(root["name"].asString());

you should transform it like that:

char* content = malloc(MAX_CONTENT_SIZE);
DynamicJsonBuffer jsonBuffer(JSON_BUFFER_SIZE);

receive(content);
JsonObject& root = jsonBuffer.parseObject(content);

Serial.println(root["name"].asString());

free(content);
Fork me on GitHub