Unable to fetch the JSON array values using jq in shell script

前端 未结 1 1261
耶瑟儿~
耶瑟儿~ 2020-12-22 13:14

I\'m trying to get the Key from the below JSON file:

I just executed the below command which will give the below JSON output

Command:

<
相关标签:
1条回答
  • 2020-12-22 13:48

    Given an array, you can use to_entries/1 to map the array an array of index and values. You could then map out to the keys and values you want on the object either using reduce or with_entries/1.

    reduce (.issues | to_entries[]) as {$key,$value} ({};
        .["JIRA-\($key + 1)"] = $value.key
    )
    

    https://jqplay.org/s/y6AFKg2dSM

    .issues | with_entries({key: "JIRA-\(.key + 1)", value: .value.key})
    

    https://jqplay.org/s/H2uxyFJn9E


    It seems like you're using a version lesser than 1.5. You'll need to make some adjustments and remove the deconstruction.

    reduce (.issues | to_entries[]) as $e ({};
        .["JIRA-\($e.key + 1)"] = $e.value.key
    )
    
    0 讨论(0)
提交回复
热议问题