Search code examples
arraysjsonjq

What's the easiest way to map JSON array values to a dictionary using jq?


How can I make a key value dictionary using jq?

If I do: cat api_fm.json | jq -r "[ .[].name, .[].status ]" I receive:

[
  "plugin",
  "c_docker_2",
  "c_docker_5",
  "c_docker_4",
  "c_docker_3",
  "c_docker_1",
  "Started",
  "Started",
  "Started",
  "Started",
  "Started",
  "Started"
]

So, I would like to map the name with the status like this:

[
   "plugin: started"
...
]

Solution

  • Here is one way:

    jq 'map("\(.name): \(.status)")'