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

sloanlance picture sloanlance  路  3Comments

rubensayshi picture rubensayshi  路  3Comments

thelonious picture thelonious  路  4Comments

lbrader picture lbrader  路  3Comments

ve3ied picture ve3ied  路  4Comments