0

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" }}

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

{
  "mykey": {
    "value": "myvalue"
  }
}
| improve this answer | |

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.