Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to check if json property is null #1049

Closed
vaz83 opened this issue Jul 15, 2019 · 1 comment
Closed

How to check if json property is null #1049

vaz83 opened this issue Jul 15, 2019 · 1 comment
Labels
v6 ArduinoJson 6

Comments

@vaz83
Copy link

vaz83 commented Jul 15, 2019

Hello,
what's the best way to check if a json property exists or has value ? i was trying to make the condition jDoc["relayInterval"]!=NULL but it's not working.
`
File configFile = SPIFFS.open("/configsa.json", "r");
size_t size = configFile.size();
// Allocate a buffer to store contents of the file.
std::unique_ptr<char[]> buf(new char[size]);
configFile.readBytes(buf.get(), size);
DynamicJsonDocument jDoc(2500);
DeserializationError error = deserializeJson(jDoc,buf.get());
if (!error)
{
if(jDoc["relayInterval"]!=NULL)
strcpy(relay_interval,jDoc["relayInterval"]);
}
'

@vaz83 vaz83 closed this as completed Jul 15, 2019
@bblanchon
Copy link
Owner

Hi @vaz83,

You cannot use NULL because ArduinoJson confuses it with 0, the integer (see explanation)

Instead, you can use nullptr or JsonObject::containsKey().

Best Regards,
Benoit

Repository owner locked and limited conversation to collaborators Aug 15, 2019
@bblanchon bblanchon added the v6 ArduinoJson 6 label Feb 6, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
v6 ArduinoJson 6
Projects
None yet
Development

No branches or pull requests

2 participants