title: How to filter JSON array in Postgres
body: <p>I currently have this <code>LEFT JOIN</code> which is part of a bigger select</p>
  
  <pre><code>LEFT JOIN (
    SELECT
      tags_components.component_id,
      array_to_json(array_agg(tags.*)) as tags
      FROM tags_components
      LEFT JOIN tags ON tags.id = tags_components.tag_id AND tags_components.component_name = 'contact'
      GROUP BY tags_components.component_id
  ) AS tags ON tags.component_id = contact.id
  </code></pre>
  
  <p>Which works as expected if component has all tags assigned. However <code>tags</code> array is always of size <code>COUNT(tags.*)</code> so for component without any tags is filled with <code>null</code>. Is there a way how filter those nulls out? I tried different things like using <code>json_strip_nulls</code> or having <code>FILTER</code> on the array but I didn't achieve the right result (JSON array containing only non-nulls)</p>