Skip to content

feat: add --export_ordered flag to produce stable JSON exports#1335

Open
zariok wants to merge 5 commits intoauth0:masterfrom
zariok:feature/sort-json
Open

feat: add --export_ordered flag to produce stable JSON exports#1335
zariok wants to merge 5 commits intoauth0:masterfrom
zariok:feature/sort-json

Conversation

@zariok
Copy link
Copy Markdown
Contributor

@zariok zariok commented Mar 25, 2026

Auth0's API returns resource attributes in inconsistent order, causing noisy diffs in version control even when nothing has changed.

🔧 Changes

Adds --sort-keys / -s CLI flag and AUTH0_SORT_JSON_KEYS config key to sort all exported JSON keys alphabetically at write time.

Implemented in dumpJSON() — the shared write utility used by all directory-format handlers — so every resource type gets the behavior automatically with no call-site changes.

📚 References

Resolves: #1186

🔬 Testing

  • npm run build passes with no TypeScript errors
  • npm test passes
  • Export with --sort-keys produces files where diff <(jq --sort-keys . file.json) file.json is empty
  • Export without --sort-keys is unchanged from current behavior
  • AUTH0_SORT_JSON_KEYS=true in config file produces the same result as the CLI flag

📝 Checklist

  • [ x ] All new/changed/fixed functionality is covered by tests (or N/A)
  • I have added documentation for all new/changed functionality (or N/A)

Auth0's API returns resource attributes in inconsistent order, causing noisy diffs in version control even when nothing has changed.

Adds `--sort-keys` / `-s` CLI flag and `AUTH0_SORT_JSON_KEYS` config key to sort all exported JSON keys alphabetically at write time.

Implemented in `dumpJSON()` — the shared write utility used by all directory-format handlers — so every resource type gets the behavior automatically with no call-site changes.

Key fix: yargs normalizes `--sort-keys` to `sortKeys` (camelCase) in the parsed argv, so the export command destructures `sortKeys` rather than `sort_keys`.
@zariok zariok requested a review from a team as a code owner March 25, 2026 03:15
@kushalshit27 kushalshit27 self-assigned this Mar 25, 2026
@kushalshit27
Copy link
Copy Markdown
Contributor

Thank you for submitting this PR! We'll review it shortly.

@zariok
Copy link
Copy Markdown
Contributor Author

zariok commented Mar 25, 2026

Manually tested via a npm run build, setting env variables and running the following:

node ~/github.com/auth0-deploy-cli/lib/index.js export -f directory -o export-sorted --sort-keys
diff <(jq --sort-keys . ./export-sorted/connections/myconnection.json) ./export-sorted/connections/myconnection.json

@kushalshit27
Copy link
Copy Markdown
Contributor

Hi, @zariok ,
It should be applicable to the YAML format too. Can you please verify that?

@zariok
Copy link
Copy Markdown
Contributor Author

zariok commented Mar 25, 2026

Hi, @zariok , It should be applicable to the YAML format too. Can you please verify that?

Let me iterate. I hit the dumpJSON. I'll update the PR when I get YAML sorted.

@zariok
Copy link
Copy Markdown
Contributor Author

zariok commented Mar 25, 2026

@kushalshit27 Ready for review again

Copy link
Copy Markdown
Contributor

@kushalshit27 kushalshit27 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update the documentation with relevant information.

kushalshit27 and others added 2 commits March 27, 2026 16:42
export_ordered instead of sort_keys
simplify sortedKeysReplacer()
add docs for this functionality
@zariok
Copy link
Copy Markdown
Contributor Author

zariok commented Mar 27, 2026

Please update the documentation with relevant information.

Done.

@zariok zariok requested a review from kushalshit27 March 27, 2026 19:54

A url for proxying requests. Only set this if you are behind a proxy.

### `--sort-keys`
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be export_ordered

@kushalshit27 kushalshit27 changed the title feat: add --sort-keys flag to produce stable JSON exports feat: add --export_ordered flag to produce stable JSON exports Mar 30, 2026
Copy link
Copy Markdown
Contributor

@kushalshit27 kushalshit27 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update the PR description to reflect current changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Sorted object dumps

2 participants