Enhancement: check if entry in JSON
step135 opened this issue · 2 comments
const char* sensor = doc["sensor"] | "unknown";
That could be ok, but when I use byte type and want to have all 256 numbers disponible, there is no solution.
I like that in Python I am able to do the check: using in
. I need to implement following logic:
byte temp = 24; //default value
if("temp" in doc["temp"]) temp = doc["temp"]; //ovewriting the value if it is in JSON
OK, chatGPT adviced me to use doc.containsKey()
, it works, but it is not documented under header "Extracting errors" at https://arduinojson.org/v7/tutorial/deserialization/
Hi @step135. This is the repository for the "Arduino_JSON" library. You are referring to the similarly named, but completely separate "ArduinoJson" library:
https://github.com/bblanchon/ArduinoJson
This library has a hasOwnProperty
function that is equivalent to the "ArduinoJson" library's containsKey
function, which is demonstrated in the example sketch:
Arduino_JSON/examples/JSONObject/JSONObject.ino
Lines 42 to 65 in ea843a9
So the feature request is not applicable to this project.