0

I need to transform this simple JSON array:

["169","19","33"]

to a more complicated JSON object for each item, like:

{
  "groups": [
    {
      "groupid": 169
    },
    {
      "groupid": 19
    },
    {
      "groupid": 33
    }
  ]
}

Currently, I do this using tools not designed for JSON, like sed, awk & whatever Unix tool — it’s dirty for that — and I fail to use JQ.

Is it possible to use a more elegant solution to transform a JSON array to a JSON object with JQ?

TRiG
  • 1,193
  • 3
  • 14
  • 30
Isopote42
  • 157

1 Answers1

3

This jq should do the trick:

jq '{groups: [ .[] | {groupid: .} ]}'