Quantcast
Channel: Active questions tagged jq - Stack Overflow
Viewing all articles
Browse latest Browse all 524

Object item and nested array items on same output line

$
0
0

I've got some data that looks like this:

{"data": [    {"startTime": "2024-12-31T00:00:00Z","data": [        {"one": "a","two": 1125.000        },        {"one": "b","two": 2119.000        },        {"one": "c","two": 0.000        }      ]    },

with multiple objects in the outer data array. What I'm failing at is outputting something like this:

startTime, one, two

which in the case of the data above would give me three lines of output.I can get one and two together, but not startTime: with jq -r '.data[] | "\(.startTime)", (.data[] | "\(.one), \(.two)" )'

2024-12-31T00:00:00Za, 1125.000b, 2119.000c, 0.000

jq -r '.data[] | "\(.startTime)", (.data[] | "\(.one), \(.two)" )' gets me the following, iterating over each of the last items ("two"):

2024-12-31T00:00:00Z, a, 1125.0002024-12-31T00:00:00Z, b, 1125.0002024-12-31T00:00:00Z, c, 1125.0002024-12-31T00:00:00Z, a, 2119.0002024-12-31T00:00:00Z, b, 2119.0002024-12-31T00:00:00Z, c, 2119.0002024-12-31T00:00:00Z, a, 0.0002024-12-31T00:00:00Z, b, 0.0002024-12-31T00:00:00Z, c, 0.000

I can't seem to hit on the right syntax.


Viewing all articles
Browse latest Browse all 524

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>