Repository navigation
fix: return null instead of NaN in /data JSON - #76
Merged
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When a value is missing,
/dataserialised it asNaN(and infinities asInfinity), e.g.{"humidity": NaN}. That is not valid JSON, so strict clients such as JavaScript'sJSON.parsefailed to read the response. This affected thecsv,jsonandxmlformats;sqlitealready returnednull.It became more common after missing values for bounded columns started being stored as empty.
Fix
SucculentAPI.data(), replaceNaNand±infwithNonebefore building the JSON response, so they are sent asnull./export(CSV) is not affected; empty cells were already correct there.Tests
TestDataJson: parses the/dataresponse as strictly as JavaScript (rejectingNaN/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.Compatibility
Clients that already read
/data(e.g. Pythonjson/requests) now getNoneinstead ofnanfor missing values. Strict JSON clients can now read the response at all.Generated by Claude Code