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:
<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
)