Skip to content

Instantly share code, notes, and snippets.

@putnamhill putnamhill/jq-snippets.sh
Last active Jan 13, 2018

Embed
What would you like to do?
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
You can’t perform that action at this time.