Noob help: Parsing json with SparkJson

That would certainly be a lot easier to parse, but would require you to send the data in the same order all the time since you're not pairing the values with the keys. Just for kicks, I wrote a little program to parse your json, to see how hard it would be. It wasn't that hard, and it works no matter what order the key value pairs are sent in. It does assume that the arrays are all that same length, and that the punctuation is as you have it.

const char json[] = "{\"history\":{\"brush twice\":[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0],\"dont murder\":[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\"no sweets\":[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,1,0],\"workout\":[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0],\"sleep by 12am\":[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0]}}";
const char keys[5][15] = {"no sweets", "workout", "sleep by 12am", "brush twice", "dont murder"};

typedef struct {
    char key[15];
    char values[45];
} datum;

datum results[5];

void setup() {
    Serial.begin(9600);
    delay(3000);
    
    for (int i=0; i<5; i++) {
        strcpy(results[i].key, keys[i]);
        char* keyStart = strstr(json, keys[i]);
        if (keyStart !=0) {
            char* dataStart = keyStart + strlen(keys[i]) + 3;
            char data[44];
            strncpy(data, dataStart, 43);
            data[43] = 0;
            strcpy(results[i].values, data);
        }else{
            strcpy(results[i].values, "no data");
        }
    }
    
    for (int i=0; i<5; i++) {
        Serial.printlnf("key: %s   values: %s", results[i].key, results[i].values);
    }
    
}

void loop() {}
1 Like

Hi there, Would you mind sending me a copy of your webhook example, please
I would highly appreciate it because I am badly stuck