Quantcast
Viewing all articles
Browse latest Browse all 524

recursive reduce arrays using jq

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 524

Trending Articles