Search code examples
jsonjqflatten

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.


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