skip to Main Content

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.

3

Answers


  1. You can use the following filter :

    .Nemo[],.Firefox[],.Codium[],.Terminals[]
    

    You can try it here.

    Login or Signup to reply.
  2. 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

    Login or Signup to reply.
  3. Another solution (demo):

    cat your_file.json | jq -r "map(values) | flatten | .[]"
    

    Prints:

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

    Or just simply (demo) thanks @pmf:

    cat your_file.json | jq "flatten[]"
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search