Skip to content

fix(jq): keep object keys in input order - #2577

Merged
chaliy merged 1 commit into
mainfrom
claude/project-thread-1mku65
Oct 7, 2026
Merged

chaliy merged 1 commit into
mainfrom
claude/project-thread-1mku65

Conversation

@chaliy

@chaliy chaliy commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Requested by Михайло · project thread

What changed

jq now prints object keys in the order they appear in the input, the same as real jq. Keys are only sorted under -S. This applies to main input (stdin or files), --slurpfile, --argjson, --jsonargs and $ARGS. A duplicate key keeps its first position and takes the last value, also matching jq.

Why

Input JSON went through serde_json::Value, whose map is sorted, so every object bashkit printed came out alphabetized. Most agent jq calls print objects, and a Debian-oracle differential run (pseudo-linus test bench) flagged this as the most common jq mismatch. We don't turn on serde_json's crate-wide preserve_order feature because that would change every other serde_json user in the workspace. Instead jq input is deserialized straight into JqJson with an order-preserving seed. The seed checks nesting depth while reading, so the TM-DOS-027 limit still applies and its error message is unchanged.

Before / After

$ echo '{"b":1,"a":2,"c":{"z":1,"y":2}}' | jq -c .
before: {"a":2,"b":1,"c":{"y":2,"z":1}}
after:  {"b":1,"a":2,"c":{"z":1,"y":2}}     # == jq 1.7.1

$ jq -nc --argjson v '{"z":1,"a":2}' '$v'
before: {"a":2,"z":1}
after:  {"z":1,"a":2}

The new jq_object_key_order_* spec cases fail on main (3 of 5; the -S and duplicate-key cases already passed) and all pass on this branch.

Risk

  • Low.
  • Scripts that relied on bashkit's accidental sorting will see real-jq order. -S still sorts.

Checklist

  • Tests added or updated (spec cases plus convert unit tests for order, duplicate keys, depth, trailing garbage)
  • Backward compatibility considered (output now matches jq; $ENV stays sorted by name for determinism)

https://claude.ai/code/session_01VscpEzxtqpCKx5eRMpywNj

Real jq preserves object key order and only sorts under -S. Input went
through serde_json::Value, whose map is sorted, so every printed object
came out alphabetized. Deserialize straight into JqJson with an
order-preserving, depth-checking seed for main input, --slurpfile,
--argjson, --jsonargs and $ARGS.

Claude-Session: https://claude.ai/code/session_01VscpEzxtqpCKx5eRMpywNj
@chaliy chaliy self-assigned this Oct 7, 2026
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
bashkit 2713974 Commit Preview URL

Branch Preview URL
Oct 07 2026, 04:43 PM

@chaliy
chaliy merged commit 3b2e6e9 into main Oct 7, 2026
43 checks passed
@chaliy
chaliy deleted the claude/project-thread-1mku65 branch October 7, 2026 17:15
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.

1 participant