Skip to content

Instantly share code, notes, and snippets.

@jkrasnay
Last active July 19, 2023 02:49
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save jkrasnay/7fbdda198561f5ca924edb9c5d7188ce to your computer and use it in GitHub Desktop.
Save jkrasnay/7fbdda198561f5ca924edb9c5d7188ce to your computer and use it in GitHub Desktop.
Processing Swagger with jq
# Convert to TSV
# Note -r flag
# to_entries creates an array of key,value maps, the trailing [] converts this array to stream items
cat api-docs.json | jq -r '.paths | to_entries[] | .key as $path | .value | to_entries[] | [.key,$path,.value.tags[0]] | @tsv'
# Transform into different JSON...
cat api-docs.json | jq '[ .paths | to_entries[] | .key as $path | .value | to_entries[] | { path:$path, method:.key, tag:.value.tags[0] } ]'
@joswr1ght
Copy link

TIL, to_entries[], thank you!

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