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: Map from nested JSON

I have the following JSON:

{
  "A": {
    "type": "string",
    "value": "value_A"
  },
  "B": {
    "type": "string",
    "value": "value_B"
  }
}

…and am trying to use JQ to result in the following:

Desired Output

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

{
  "A": "value_A",
  "B": "value_B"
}

…where the key takes the direct value of node.value.


My current attempt:

.[] | {value}

…returns the following:

{
  "value": "value_A"
}
{
  "value": "value_B"
}

How can I use JQ to produce the desired JSON?

>Solution :

You don’t need with_entries.

map_values(.value)

Online 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