I am trying to flatten a JSON file by using jq command. But the output got duplicated.
Please see my jqplay here: https://jqplay.org/s/gwvMIH_fed
My input JSON:<
Each .[] is like a "for" loop, so the multiplicative behavior you observe is essentially the result of having nested for loops. It would seem that what you want is closer to:
.value[] as $v
| $v.timeseries[].data[] as $d
| {"apiId": $v.id,
"metrics": $v.name.value,
"timestamp": $d.timeStamp,
"value": $d.average }
With your JSON as input, this produces two JSON objects, though the second of these differs very slightly from what you give as the expected output.