Extracting data from JSON string

Any idea how I can either correctly extract data from the JSON string below or better format my JSON string so that it is more compatible with the JSON parser? The JSON string (shown below) has been post processed on a separate server that we are running internally, so we have control over the formatting.

Presently, I get NULL for the value of sensor when using the code shown below. But when I use the commented JSON string and commented reference, I get the correct value.

#include <ArduinoJson.h>

//char json[] = "{\"sensor\":\"gps\",\"time\":1351824120,\"data\":[48.756080,2.302038]}";
char json[] = "{\"data\": [{\"time\": 26, \"headsign\": \"Wellington via Veterans Senior Center\", \"id\": \"38428504\"}, {\"time\": 36, \"headsign\": \"Wellington\", \"id\": \"38428529\"}, {\"time\": 56, \"headsign\": \"Wellington\", \"id\": \"38428543\"}, {\"time\": 74, \"headsign\": \"Wellington\", \"id\": \"38428494\"}]}";

StaticJsonBuffer<500> jsonBuffer;
JsonObject& root = jsonBuffer.parseObject(json);

void tickTock() {
    //const char* sensor = root["sensor"];
    const char* sensor = root["data"][0]["id"];
    Particle.publish("sensor", sensor);


Timer timer(5000, tickTock);
void setup() {

I haven’t tried yet, but have you tried increasing the buffer size?
There is a formula to calculate the buffer size required depending on number of fields, nesting depth and so forth, but for a quick check, just double to 1000.

That was it! I had increased the buffer size to 500, so I did not think going to 1000 would work. I had assumed that the buffer only needed to be the size of the string. Can you point to any guide on how to correctly calculate buffer size?


Here is some discussion of the topic