Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • A ArduinoJson
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 24
    • Issues 24
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 0
    • Merge requests 0
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Benoît Blanchon
  • ArduinoJson
  • Issues
  • #973
Closed
Open
Issue created Apr 23, 2019 by Administrator@rootContributor

Unquoted NaN is not a valid JSON value

Created by: glrs

I have noticed that once I unplug a DHT sensor from arduino, and then try to read from it, it returns nan temp = nan & hum = nan. With the next piece of code, I create a JSON object and send it to RPi. When the sensor is disconnected, the returned nan values are transformed into NaN (unquoted) by the ArduinoJson. According to json.org the only acceptable unquoted value for a missing/undefined value is null. Passing unquoted NaN, causes problems to parse that JSON object - at least - in Javascript.

Here is part of my code:

#include <ArduinoJson.h>

#include <DHT.h>
#include <DHT_U.h>

float hum;
float temp;
...
void loop() {
  hum = dht.readHumidity();
  temp= dht.readTemperature();

  StaticJsonDocument<200> root;

  root["AirTemp"] = temp;
  root["Humidity"] = hum;

  serializeJson(root, Serial);
  delay(30000);
}

I suggest to either pass "NaN" as string (I mean quoted, not String datatype necessarily), or just pass null.

Assignee
Assign to
Time tracking