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,181
  • 3
  • 13
  • 30
user5525652
  • 157
  • 1
  • 4
  • 14

1 Answers1

2

This jq should do the trick:

jq '{groups: [ .[] | {groupid: .} ]}'
Gordon Davisson
  • 11,216
  • 4
  • 28
  • 33