Skip to content

Instantly share code, notes, and snippets.

Last active June 10, 2022 15:27
What would you like to do?
Escape JSON fields with numbers or dashes to avoid jq compile errors
echo '{"my-field": "something"}' > example.json
cat example.json | jq '.my-field' # Incorrect
# jq: error: key/0 is not defined at <top-level>, line 1: .my-field
# jq: 1 compile error
cat example.json | jq '."my-field"' # Correct
# "something"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment