Skip to content

Instantly share code, notes, and snippets.

@duboisf
Created November 5, 2025 15:10
Show Gist options
  • Select an option

  • Save duboisf/3676b2ac80e4c03790f35fcea42e9774 to your computer and use it in GitHub Desktop.

Select an option

Save duboisf/3676b2ac80e4c03790f35fcea42e9774 to your computer and use it in GitHub Desktop.
Sort aws iam policy document by sid, and sort action and resource arrays
#!/bin/sh
jq '
.Statement |= sort_by(.Sid) |
.Statement |= map(
if .Action then .Action |= (if type == "array" then sort else . end) else . end |
if .Resource then .Resource |= (if type == "array" then sort else . end) else . end
)
' \
| jq --sort-keys .
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment