Skip to content

Instantly share code, notes, and snippets.

@putnamhill
Last active January 13, 2018 16:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save putnamhill/b3d1ce4e91faffc5da25e6389db586fc to your computer and use it in GitHub Desktop.
Save putnamhill/b3d1ce4e91faffc5da25e6389db586fc to your computer and use it in GitHub Desktop.
collection of miscellaneous jq snippets
# print value pairs from an array in lower case
jq --raw-output '.[] | "\(.key_1 | ascii_downcase) \(.key_2 | ascii_downcase)"'
# convert `key=value` lines into `{"key":"value"}` json
jq --raw-input 'split("=") | {(.[0]):.[1]}' some.conf | jq --slurp 'add'
# validate json (bad)
echo '{hello: "there"}' | jq . >/dev/null 2>&1 && echo good json || echo bad json
bad json
# validate json (good)
echo '{"hello": "there"}' | jq . >/dev/null 2>&1 && echo good json || echo bad json
good json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment