Using jq to fetch key value from json output

后端 未结 3 1055
暖寄归人
暖寄归人 2021-02-12 08:29

I have a file that looks as below:

{
  \"repositories\": [
   {
    \"id\": \"156c48fc-f208-43e8-a631-4d12deb89fa4\",
    \"namespace\": \"rhel12\",
    \"namesp         


        
3条回答
  •  心在旅途
    2021-02-12 08:46

    Here is another solution. Assuming the requirements

    I want to get only name values with each of them in a new line so that I can use while read -r line.

    Can you please how can i get output in format rhel12/rhel6.6 In other words, I need o/p in format namespace/name

    if the data is in data.json then the command

    jq -M -r '.repositories[] | "\(.namespace)/\(.name)"' data.json
    

    should produce

    rhel12/rhel6.6
    rhel12/rhel7
    

提交回复
热议问题