If read the wiki, but can't find a anwer. I'm feeling I'm overlooking something but can
t find out the correct way.
Let's say I have this simple json:
{
"object1":
{
"key": "val"
},
"object2":
{
"key": "val"
}
}
Now, I want to detect if object2 exists at all, before writing to it.
When trying to find out it a object is empty or not:
JsonObject& obj = json[char_object];
if (obj.containsKey(char_item))
This would be false when the key doesn't exist _or_ the entire object doesn't exist. How can I find out if the object even exist before doing a containsKey ?
char json[] = "{\"object1\":{},\"object2\":{}}";
JsonObject& root = jsonBuffer.parseObject(json);
if (root.containsKey("object2")) {
Serial.println("Found object2 !");
}
Thank you!
You're welcome, thanks for using ArduinoJson.
Don't hesitated to edit the wiki if you think you can improve it.
In particular, feel free to add you projects to Projects using ArduinoJson.
Also, a GitHub star is always appreciated :wink:
Most helpful comment