Last active
June 10, 2022 15:27
-
-
Save magickatt/50f5bdbfaf606c675f3147e290e4f118 to your computer and use it in GitHub Desktop.
Escape JSON fields with numbers or dashes to avoid jq compile errors
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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