Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@magickatt
Last active June 10, 2022 15:27
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 magickatt/50f5bdbfaf606c675f3147e290e4f118 to your computer and use it in GitHub Desktop.
Save magickatt/50f5bdbfaf606c675f3147e290e4f118 to your computer and use it in GitHub Desktop.
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