Skip to content

Instantly share code, notes, and snippets.

@arbakker
Last active September 27, 2021 20:42
Show Gist options
  • Save arbakker/4e0eaf8251b2f96c5f584b69630e094c to your computer and use it in GitHub Desktop.
Save arbakker/4e0eaf8251b2f96c5f584b69630e094c to your computer and use it in GitHub Desktop.
Add property to item in array where condition jq
#!/usr/bin/env bash
test='[
{"foo": "parrot"},
{"foo": "fjords"}
]'
jq "[.[] | select(.foo != \"parrot\")] + [.[] | select(.foo == \"parrot\") + {bar: \"ex-parrot\"}]" <<< $test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment