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

Prefix elements of string array with key in JQ

I have a 2 jsons with its environment and the applications in it.
To compare the different (missing applications) between the 2 json,
I want to simplify the json in to an array, so that I can use minus to find the different,
but I failed to set the key as a prefix of the array.

example input:

{
  "qa": [
    "app-a",
    "app-b",
    "app-c"
  ],
  "prod": [
    "app-a",
    "app-c",
    "app-e"
  ]
}

expected 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

[
  "qa:app-a",
  "qa:app-b",
  "qa:app-c",
  "prod:app-a",
  "prod:app-c",
  "prod:app-e",
]

>Solution :

Here you go:

to_entries | map(.key + ":" + .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