Jq: How can I parse a json whose key starts from numeric string

Created on 23 Apr 2014  ·  3Comments  ·  Source: stedolan/jq

I have a json like

{"2xx_count":10,"3xx_count":11}

but, I get errors as followings:

$ echo '{"2xx_count":10,"3xx_count":11}' | jq .2xx_count
error: syntax error, unexpected IDENT, expecting $end
.2xx_count
  ^^^^^^^^
1 compile error
support

Most helpful comment

echo '{"2xx_count":10,"3xx_count":11}' | jq '.["2xx_count"]'

All 3 comments

echo '{"2xx_count":10,"3xx_count":11}' | jq '.["2xx_count"]'

@lluchs thanks!

@lluchs

How to do that with key_name as variable ? For example

cat data.json | jq '.["$1"]' where $1 is the first paremeter ?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ghost picture ghost  ·  4Comments

tbelaire picture tbelaire  ·  4Comments

thedward picture thedward  ·  3Comments

thelonious picture thelonious  ·  4Comments

rokka-n picture rokka-n  ·  4Comments