How to use jq to create an object with an arbitrary key from a sub array?

This was actually relatively straight forward:

.things | .[] | {name: .name, category: .params | .[] | select(.key=="category") | .value }

Your params almost looks like key/value entries, so you could create an object out of them by passing the array to from_entries. So to combine everything, you merely need to do this:

.things | map({name} + (.params | from_entries))

This yields:

[
  {
    "name": "foo",
    "key1": "val1",
    "category": "thefoocategory"
  },
  {
    "name": "bar",
    "key1": "val1",
    "category": "thebarcategory"
  }
]

Tags:

Json

Jq