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

Flatten multiple arrays keeping order

I have a json object like:

{
  "Nemo": [
    3694756688,
    3694756832,
    3694756650
  ],
  "Firefox": [
    3694756795,
    3694756407,
    3694756412,
    3694756395
  ],
  "Codium": [
    3694756035,
    3694756383,
    3694756378
  ],
  "Terminals": [
    3694756804,
    3694756802,
    3694756428
}

I need output like:

3694756688
3694756832
3694756650
3694756795
3694756407
3694756412
3694756395
3694756035
3694756383
3694756378
3694756804
3694756802
3694756428

The order is important. How can i do it 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 :

keys_unsorted gives you the keys in their original order. You can use them to iterate:

.[keys_unsorted[]][]

Demo

You could also just use .[] to iterate over the object’s fields, which for current versions of jq produces the same result, but that is not guaranteed to stay that way:

.[][]

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