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 extracting the name and the value of objects as an array

I have this code and I need to get the keys and the values of the "filterFeatureGroup" object with JQ.

{
  "filterFeatureGroup": {
    "Hauttyp": [
      "Normal"
    ],
    "Deckkraft": [
      "Mittlere Deckkraft"
    ],
    "Grundfarbe": [
      "Grau"
    ],
    "Produkteigenschaften": [
      "Vegan"
    ],
    "Textur / Konsistenz / Applikation": [
      "Stift"
    ]
  }
}

My desired output is:

["Hauttyp: Normal", "Deckkraft: Grau", "Produkteigenschaften: Vegan"]

I have tried to put together the keys[] and values[] of the object but then I ended up with multiplying the elements in the 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

jq ".filterFeatureGroup| (keys[]| split(",")) + (values[])| join(": ")"

Would anyone be able to help?

>Solution :

I have tried to put together the keys[] and values[] of the object

Use to_entries for that

.filterFeatureGroup | to_entries | map("\(.key): \(.value[0])")

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