Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

jq: mapping all values of an object

Say I have an object like so:

{
  "key1": "value1",
  "key2": "value2",
  "key3": "value3"
}

I want to use jq to convert this to:

{
  "key1": {
    "innerkey": "value1"
  },
  "key2": {
    "innerkey": "value2"
  },
  "key3": {
    "innerkey": "value3"
  }
}

i.e. I want to apply a mapping to every value in the object, that converts $value to {"innerkey": $value}. How can I achieve this with jq?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

It’s literally called map_values. Use it like this

map_values({innerkey:.})

Demo

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading