Skip to content

fix(fetch): preserve JSON body key order - #11049

Closed
proggeramlug wants to merge 3 commits into
mainfrom
fix/10392-fetch-json-key-order
Closed

proggeramlug wants to merge 3 commits into
mainfrom
fix/10392-fetch-json-key-order

Conversation

@proggeramlug

@proggeramlug proggeramlug commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • parse Request.json() and Response.json() bodies through Perry's JavaScript JSON parser instead of serde_json::Value's sorted map
  • preserve document order for non-index keys while retaining JavaScript's numeric-key ordering
  • reject invalid bodies with the runtime parser's JavaScript error value
  • add focused unit and end-to-end compatibility coverage

Fixes #10392

Testing

  • cargo fmt --all -- --check
  • cargo check -p perry-stdlib
  • cargo test -p perry-stdlib fetch_json_preserves_document_key_order -- --nocapture
  • cargo test --release -p perry-stdlib fetch_json_preserves_document_key_order -- --nocapture on perrymaster
  • scripts/check_file_size.sh
  • python3 scripts/raw_handle_debt.py --check
  • python3 scripts/string_payload_access_inventory.py
  • python3 scripts/unrooted_local_shape.py --check
  • coherent release build of perry, perry-runtime-static, and perry-stdlib-static on perrymaster
  • compiled test_gap_10392_fetch_json_key_order.ts output compared byte-for-byte with Node

CI note

The lint job has one base failure: python3 benchmarks/ci_public_baseline_check.py exits 2 on a clean detached origin/main checkout at f5cfbff882. This is tracked in #10799. All patch-related lint gates pass.

Summary by CodeRabbit

  • Bug Fixes
    • Request.json() and Response.json() preserve the order of non-numeric keys in JSON documents. Integer-like keys continue to follow JavaScript’s numeric-key ordering.
    • JSON parsing better matches JavaScript’s number and error behavior. When parsing fails, these methods now reject with the parser’s error value rather than a formatted JSON parse error.

@coderabbitai

coderabbitai Bot commented Sep 22, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: 78cdf5ed-71fa-4021-8ebd-6b312d8462f9

📥 Commits

Reviewing files that changed from the base of the PR and between 02f7ead and 16be733.

📒 Files selected for processing (2)
  • crates/perry-stdlib/src/fetch/mod.rs
  • scripts/unrooted_local_shape_baseline.json

Included review availability: Your plan provides up to 8 included reviews per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

Request.json() and Response.json() now parse bodies through the runtime JSON parser. Non-index keys retain document order, while integer-like keys follow JavaScript ordering. Tests cover the resulting key order.

Changes

Fetch JSON parsing

Layer / File(s) Summary
Runtime JSON parsing and Fetch integration
crates/perry-stdlib/src/fetch/mod.rs, crates/perry-stdlib/src/fetch/tests.rs, test-files/test_gap_10392_fetch_json_key_order.ts, changelog.d/10392-fetch-json-key-order.md, scripts/unrooted_local_shape_baseline.json
A shared body parser calls the runtime JSON parser. Request.json() and Response.json() use the parsed value or reject with the returned error. Tests check that integer-like keys come first and non-index keys retain document order. The changelog records the behavior, and the baseline removes the Fetch module entry and updates its total.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~15 minutes

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to 16be7

The change appears ready to merge after normal checks; no actionable risk is established.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: preserving JSON body key order in fetch APIs.
Description check ✅ Passed The description explains the change, includes the related issue, lists concrete testing commands, and reports CI context. It uses “Testing” instead of the template’s “Test plan” heading and does not i…
Linked Issues check ✅ Passed Issue [#10392] requires Request.json() and Response.json() to preserve document order for non-index string keys and retain JavaScript integer-key ordering. The fetch implementation now uses the ru…
Out of Scope Changes check ✅ Passed The changed files support [#10392]. The implementation fixes both fetch JSON helpers. The changelog and regression tests document and verify the behavior. The unrooted shape baseline update supports t…
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 3 files. (1 skipped: 1 …
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@proggeramlug

Copy link
Copy Markdown
Contributor Author

Landed on main in merge train 265 (#11108), released as v0.5.1648 at 9d26936298.

Cherry-picked from this PR's head 16be733d35 and validated as one tree with 15 other PRs — CI 22/22 green, all 6 gap-suite shards. A train rebase gives the commits new SHAs, so GitHub cannot auto-close the source PR; closing by hand.

Nothing needed from you. Thanks.

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.

Request.json() / Response.json() return keys alphabetically sorted instead of in document order

1 participant