PlatformIO Community

Arduino json parsing

Hi guys…

I am working with platformio, esp32 and with this lib . …

I would like to parse a json coming from the cloud and to print out the payload content…

I have done this code :

void messageHandler(char *topic, byte *payload, unsigned int length)
{
  Serial.print("incoming: ");
  Serial.println(topic);

  StaticJsonDocument<200> doc1, doc2;
  deserializeJson(doc1, payload);
  deserializeJson(doc2, doc1["name"]);

  const char *message = doc1["message"];
  const char *message2 = doc1["name"];

  Serial.println(message);
  Serial.println(message2);
}

How can I print out the payload without knowing in advance?

Thanks

You can iterate through an a JSON object without knowing its keys in advance: https://arduinojson.org/v6/api/jsonobject/begin_end/https://arduinojson.org/v6/api/jsonobject/begin_end.