I have a table with json field where array of objects is stored. I would like to query this table and for each returned row return only subset of json array objects by filtering
You can use json_array_elements to unnest JSON and array_agg to nest it back after filtering. Something like this:
json_array_elements
array_agg
SELECT t.id, array_to_json(array_agg(j)) FROM your_table t, json_array_elements(t.jsonColumn) j WHERE j->>'field' = 'abc' GROUP BY id;