Skip to content

fix: return null instead of NaN in /data JSON - #76

Merged
firefly-cpp merged 1 commit into
mainfrom
fix/nan-json
Nov 2, 2026
Merged

firefly-cpp merged 1 commit into
mainfrom
fix/nan-json

Conversation

@firefly-cpp

Copy link
Copy Markdown
Owner

Problem

When a value is missing, /data serialised it as NaN (and infinities as Infinity), e.g. {"humidity": NaN}. That is not valid JSON, so strict clients such as JavaScript's JSON.parse failed to read the response. This affected the csv, json and xml formats; sqlite already returned null.

It became more common after missing values for bounded columns started being stored as empty.

Fix

  • In SucculentAPI.data(), replace NaN and ±inf with None before building the JSON response, so they are sent as null.
  • All other values are unchanged. /export (CSV) is not affected; empty cells were already correct there.

Tests

  • New TestDataJson: parses the /data response as strictly as JavaScript (rejecting NaN/Infinity) for all four formats, plus a case with an infinite value. Four of these fail on the previous code and pass with the fix.
  • Full suite: 30 passed.

Compatibility

Clients that already read /data (e.g. Python json/requests) now get None instead of nan for missing values. Strict JSON clients can now read the response at all.


Generated by Claude Code

Missing values were serialised as NaN (and infinities as Infinity),
which is not valid JSON, so strict clients such as JavaScript's
JSON.parse could not read the /data response. Affected the csv, json
and xml formats; sqlite already returned null.

- Replace NaN and +/-inf with None before building the /data response
- Add tests that parse /data strictly for all four formats

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VCvw8haRnmyrVKrLkz5Yf8
@firefly-cpp
firefly-cpp merged commit ff7edd0 into main Nov 2, 2026
12 checks passed
@firefly-cpp
firefly-cpp deleted the fix/nan-json branch November 2, 2026 21:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants