2

I am lost with an easy-looking JQ problem. Given a key-value object, I want to transform the value into a nested object with a "value"-key. I tried permutations with 'to_entries' and native output as well as the {}-output option, but without success. I'm convinced that there is a rather obvious solution, but I cannot find it.

Input:

{ "mykey" : "myvalue" }

Desired output:

{ "mykey" : { "value" : "myvalue" }}

1 Answer 1

5
$ jq '{(keys[0]): {value:.[keys[0]]}} ' <<< '{ "mykey" : "myvalue" }'

{
  "mykey": {
    "value": "myvalue"
  }
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .