Repository navigation
fix(jq): handle serde_json arbitrary_precision numbers - #2965
Conversation
With serde_json/arbitrary_precision enabled via feature unification, non-integer numbers arrive as a single-entry map with the private key $serde_json::private::Number instead of visit_f64. JqSeed::visit_map now detects that shape and returns JqJson::Number with the exact text, so jq input, --argjson, and streams keep working in either build. Closes #2964
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
bashkit | fac4a60 | Commit Preview URL Branch Preview URL |
Nov 22 2026, 03:01 AM |
There was a problem hiding this comment.
Correct, well-scoped fix for the feature-unification hazard in #2964. JqSeed is the only custom deserialize_any visitor in the jq path and all three entry points (parse_json_value, parse_json_stream, parse_json_stream_partial) go through it, so the single visit_map shape check covers main input, --argjson/--jsonargs, --slurpfile, and streams. The single-entry check with the multi-entry fall-through mirrors serde_json::Value's own AP behavior, and the feature-independent unit test plus the knowledge update match the repo's contribution rules. Two worth-considering items below, no blockers.
Review verdict (push
|
Address PR review: feed the second entry through the same last-wins dedupe as the normal path and pin the two-entry fall-through with a companion test.
There was a problem hiding this comment.
Re-reviewed the new push (92a5816). Both P2s from the prior review are addressed: the second entry in the token-led fall-through now goes through the same last-wins/first-position dedupe, and token_led_object_with_second_key_stays_object pins the must-stay-an-object branch. One minor follow-up below, no blockers.
Only interpret single-entry $serde_json::private::Number map as Number when the build actually enabled arbitrary_precision (runtime OnceLock via 2.50 round-trip). Real objects with that key stay Objects without the feature; with it they match serde_json::Value parity. Add single_entry_token_object_matches_build_mode to pin both modes.
There was a problem hiding this comment.
Re-reviewed push c823ac8. The runtime probe design is sound (it exercises the same deserialize_any path the fix relies on, so probe and parser cannot disagree by construction), all three entry points set handle_token, child() propagates it, and the knowledge doc matches the code. But this push makes automated dual-build coverage load-bearing, and it does not exist — one new finding below.
Gate private-token number handling on runtime arbitrary_precision detection so real single-entry objects stay Objects without the feature. Extend fall-through test with duplicate-key collapse and add CI leg running jq tests with serde_json/arbitrary_precision unified on.
|
Review follow-ups addressed in fac4a60: (1) fall-through test now includes a duplicate private-token case asserting last-wins collapse to a single entry; (2) CI leg added running jq tests with serde_json/arbitrary_precision unified on. Also gated token handling on runtime feature detection so real single-entry objects stay Objects without the feature. |
What changed
Fixes jq misreading every non-integer number when any crate in the build enables serde_json/arbitrary_precision via feature unification. JqSeed::visit_map now detects the single-entry private-token map shape and returns JqJson::Number with the exact text.
Why
Closes #2964. Without this, decimals become one-key objects, breaking arithmetic (exit 5) and silently wrong comparisons (exit 0).
Before / After
With serde_json/arbitrary_precision on, before fix: round_trip_preserves_float_zero_decimal fails; echo '{"a": 1.5}' | jq '.a + 1' errors; map(select(. > 1)) returns objects. After fix: '{"a":1.5,"b":2}', '2.5', '[2.5,10]' as expected. Full lib suite passes in both builds (3507 tests with arbitrary_precision).
Risk
Checklist
Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.