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 use not designed JSON tool for that, like sed, awk & whatever Unix tool - it's dirty for that - , and I fail to use JQ.

It's possible to use more elegant solution to transform JSON array to JSON Object with JQ ?

Best regards,

user5525652
  • 137
  • 1
  • 4
  • 12

1 Answers1

2

This jq should do the trick:

jq '{groups: [ .[] | {groupid: .} ]}'
Gordon Davisson
  • 11,036
  • 3
  • 27
  • 33