postgresql: grouping with json columns, eliminating nulls
Unless I don't know your actual query, you can JOIN rows where col_a is not null with rows where col_b is not null.




create table test(my_id int, col_a json, col_b json);
insert into test values
(5001, '["a", "b"]', null),
(5001, null, '["c", "d"]');






    select t1.my_id, t1.col_a, t2.col_b 
    from test t1
    inner join (select my_id, col_b
                from test
                where col_b is not null) t2
    on t1.my_id = t2.my_id
    where t1.col_a is not null;



my_id | col_a      | col_b     
----: | :--------- | :---------
 5001 | [&quot;a&quot;, &quot;b&quot;] | [&quot;c&quot;, &quot;d&quot;]



dbfiddle here