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

recursive reduce arrays using jq

$
0
0

How can I recursive find all arrays in object and reduce them to first item ?

I tried to detect array using if .[0]? == "" then .[0] else . end but it not output anything if current object is not array.

input:

{"a": 1,"b": [    1,    2,    3  ],"c": [    {"a": 1,"b": [        1,        2,        3      ],"c": {"a": 1,"b": [          1,          2,          3        ]      }    },    {"a": 1,"b": [        1,        2,        3      ],"c": {"a": 1,"b": [          1,          2,          3        ]      }    },    {"a": 1,"b": [        1,        2,        3      ],"c": {"a": 1,"b": [          1,          2,          3        ]      }    }  ]}

output:

{"a": 1,"b": [    1  ],"c": [    {"a": 1,"b": [        1      ],"c": {"a": 1,"b": [          1        ]      }    }  ]}

Viewing all articles
Browse latest Browse all 657

Trending Articles



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