When I pretty print a json file using
cat xx.json | jq .
, it prints every field in its own line. This causes extremely long output if, e.g., the json file contains arrays of x y coordinates.
Is there a way to use jq
to print each level-one field (i.e. direct child of the root) of the json object in its own line?
More generally, is there a way to expand the json object up to level k
, so that each level k child is printed in one line that contains its descendants (with levels greater than k).
-- Clarification:
A small illustrative example is:
echo '{"type":"MultiPolygon","coordinates":[[[[-94.9065,38.9884],[-94.8682,39.0596],[-94.6053,39.0432],[-94.6108,38.8460],[-94.6108,38.7365],[-94.9668,38.7365],[-95.0544,38.7365],[-95.0544,38.9829]]]]}"' | jq .
generates:
{
"type": "MultiPolygon",
"coordinates": [
[
[
[
-94.9065,
38.9884
],
[
-94.8682,
39.0596
],
[
-94.6053,
39.0432
],
[
-94.6108,
38.846
],
[
-94.6108,
38.7365
],
[
-94.9668,
38.7365
],
[
-95.0544,
38.7365
],
[
-95.0544,
38.9829
]
]
]
]
}
I'd like to print all of the value of "coordinates"
and the value of each of its sibling in one line (and more generally, I'd like to achieve the same if the coordinates
field is at level k of the root, instead of level 1).