How to get key names from JSON using jq

前端 未结 7 1025
[愿得一人]
[愿得一人] 2020-11-29 22:15

curl http://testhost.test.com:8080/application/app/version | jq \'.version\' | jq \'.[]\'

The above command outputs only the values as below:

         


        
7条回答
  •  离开以前
    2020-11-29 22:31

    Here's another way of getting a Bash array with the example JSON given by @anubhava in his answer:

    arr=($(jq --raw-output 'keys_unsorted | @sh' file.json))
    
    echo ${arr[0]}    # 'Archiver-Version'
    echo ${arr[1]}    # 'Build-Id'
    echo ${arr[2]}    # 'Build-Jdk'
    

提交回复
热议问题