Skip to content

Parse JSON floats exactly with serde_json's float_roundtrip - #1694

Open
aradalvand wants to merge 1 commit into
RedisJSON:masterfrom
aradalvand:float-roundtrip
Open

aradalvand wants to merge 1 commit into
RedisJSON:masterfrom
aradalvand:float-roundtrip

Conversation

@aradalvand

@aradalvand aradalvand commented Nov 11, 2026 •

Copy link
Copy Markdown

Fixes #1690.

serde_json parses floats with best-effort precision unless its float_roundtrip feature is on, so JSON.SET sometimes stores an adjacent double instead of the one it was given. This affects far more than 0.9999999999999999: round-tripping 3,999 random doubles through JSON.SET/JSON.GET on Redis 8.10.2, both builds from the same master commit:

Module Doubles changed 0.9999999999999999 comes back as
Stock (8.1.0) 814 1.0
master, unchanged 814 1.0
master + float_roundtrip 0 0.9999999999999999

Every change was in the last digit, e.g. 0.36995516654807925 → 0.3699551665480793.

Changes

  • Cargo.toml: add float_roundtrip to the serde_json features. Cargo unifies features, so this also covers ijson's use of serde_json.
  • tests/pytest/test.py:

Trade-off

Per serde_json's docs, float_roundtrip costs about 2× on float parsing, in exchange for exact values.

Testing

Built in a Debian trixie container and loaded into redis:8.10.2. The new test and the Yelp fixture pass with the fix and fail without it. cargo test -p json_path and cargo test -p redis_json pass.

🤖 Generated with Claude Code

https://claude.ai/code/session_01XUNs4unCWEtK5q25xYbvgz

serde_json parses floats with best-effort precision by default, which
stores some values as an adjacent double: `0.9999999999999999` became
`1.0`, and about one in five random doubles changed in their last digit
between `JSON.SET` and `JSON.GET`. Enabling `float_roundtrip` makes
parsing exact.

The new test covers values that changed before, and
`pass-jsonsl-yelp.json`, previously skipped for float precision, now
round-trips too.

Fixes RedisJSON#1690.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XUNs4unCWEtK5q25xYbvgz
@CLAassistant

CLAassistant commented Nov 11, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

This branch has not been deployed

No deployments
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.

JSON.SET rounds 0.9999999999999999 to 1.0, changing strict numeric filter results

2 participants