Repository navigation
fix JSON output panicking on infinite and NaN floats - #7725
Merged
Merged
Conversation
JSON numbers can't represent infinity or NaN, so the JSON writer panicked with "json: unsupported value: +Inf" on any such value, e.g., the result of a float division by zero like 1.0/0. That broke -f json, -j, -J, and json_stringify(), and super db serve returned a 200 response cut off at the first such value. These values are now written as the strings "+Inf", "-Inf", and "NaN", as they appear in SUP. The writer already turns other values JSON can't represent, such as durations, timestamps, and IP addresses, into strings.
mattnibs
approved these changes
Nov 25, 2026
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.
JSON numbers can't represent infinity or NaN, so the JSON writer panicked on any such value. That's easy to hit, because a float division by zero gives
+Inf,-Inf, orNaN(integer division by zero gives anerrorvalue instead). It affected-f json,-j,-J, andjson_stringify(). Throughsuper db serve, the server caught the panic but returned a 200 OK cut off at the first such value, e.g.,[1]forvalues 1, 1.0/0, 3.On current tip of
main, commit f7e3eb6:On this branch:
These values are now written as the strings
"+Inf","-Inf", and"NaN", as they appear in SUP. That follows how the writer already handles durations, timestamps, IP addresses, and other values JSON can't represent, and float map keys were already written this way (map{+Inf:1}gives{"+Inf":1}). The strings cast back to floats with'+Inf'::float64. This Gist compares other choices, such asnull, the Postgres spelling"Infinity", and what DuckDB, jq, Python, and JavaScript do.The new ztest fails on
main. Timing of JSON output for 10 million floats is unchanged.