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,

2

This jq should do the trick:

jq '{groups: [ .[] | {groupid: .} ]}'
1
  • That works, thank you very much! – user5525652 Jan 28 at 8:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.