Parse or view JSON data fields using JQ tool utility where field names have a “-” dash in the key name

前端 未结 4 612
既然无缘
既然无缘 2020-12-12 08:05

I have a JSON data file (as shown below) and I\'m trying to find field values using jq utility.

It\'s working fine except for fields if the key name contains a

4条回答
  •  一整个雨季
    2020-12-12 08:32

    I don't know about jq, but you put python in the tags so:

    $ cat test.json | python -c "import sys, json; print(json.load(sys.stdin)['content']['book1']['field-three']['name'])"
    THIRD
    

    or without the pipe:

    $ python -c "import json; print(json.load(open('test.json'))['content']['book1']['field-three']['name'])"
    

提交回复
热议问题