jq: Cannot index array with string

后端 未结 1 1898
猫巷女王i
猫巷女王i 2020-12-13 08:22

I have the following in a file (which I will call \"myfile\"):

[{
    \"id\": 123,
    \"name\": \"John\",
    \"aux\": [{
        \"abc\": \"random\",
              


        
相关标签:
1条回答
  • 2020-12-13 08:47

    It should be:

    jq '.[].aux[].def' file.json
    

    .[] iterates over the outer array, .aux[] then iterates over the the aux array of every node and .def prints their .def property.

    This will output:

    "I want this"
    

    If you want to get rid of the double quotes pass -r (--raw) to jq:

    jq -r '.[].aux[].def' file.json
    

    Output:

    I want this
    
    0 讨论(0)
提交回复
热议问题