Skip to content

Instantly share code, notes, and snippets.

@goofrider
Last active September 26, 2020 19:42
Show Gist options
  • Save goofrider/e6fb8c366e799230ed79c8ab646bff7b to your computer and use it in GitHub Desktop.
Save goofrider/e6fb8c366e799230ed79c8ab646bff7b to your computer and use it in GitHub Desktop.
[jq cheatsheet] Basic jq usage #jq #json
#### jq: sort by key value
jq '. | sort_by(.name)'
# Input
# [{name: "casey","age":54}, {"name": "Mary", "age":31}, {"name": "John", "age":20}]
# Output:
# [{"name": "John", "age": 20}, {"name": "Mary", "age":31}.{"name": "casey", "age":54}]
#### jq: filter by key value
jq ' .[] | select (.paid == "yes")'
# Input
# [{"name": "casey", "paid": "no"}, {"name": "Mary", "paid": "yes"}, {"name": "John", "paid": "no"}]
# Output:
# {"name": "Mary", "paid": "yes"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment