title: Merge 2 json inet arrays and select where in cidr or equals
body: <p>I've got a column (definition is the column name) in the table scopes. This column contains a json object which looks like the following:</p>
  <pre><code>{
    &quot;ips&quot;: {
      &quot;ranges&quot;: [
        &quot;1.1.1.1/16&quot;,
        &quot;2.2.2.2/24&quot;
      ],
      &quot;addresses&quot;: [
        &quot;8.8.8.8&quot;,
        &quot;4.4.4.4&quot;
      ]
    }
  }
  </code></pre>
  <p>I am trying to select all the IPs from a different table (table is called ips and the ips in this table are in the 'ip' column) which are either an IP in the addresses json array or are in the range of one of the ranges in the ranges array in the json object.</p>
  <p>Currently im not proceeding past</p>
  <pre><code>select jsonb_array_elements((scopes.definition-&gt;'ips'-&gt;&gt;'ranges')::jsonb || (scopes.definition-&gt;'ips'-&gt;&gt;'addresses')::jsonb) as ip_assets from scopes;
  </code></pre>
  <p>which returns</p>
  <pre><code>     ip_assets
  -------------------
   &quot;1.1.1.1/16&quot;
   &quot;2.2.2.2/24&quot;
   &quot;8.8.8.8&quot;
   &quot;4.4.4.4&quot;
  </code></pre>
  <p>The idea was to somehow get these rows together as an inet[], so it can be used in something like:</p>
  <pre><code>select ip from ips where &lt;&lt; any (array['1.1.1.1/16', '2.2.2.2/24', '8.8.8.8', '4.4.4.4']::inet[]);
  </code></pre>
  <p>(where the hardcoded array is replaced with e.g. a subselect which contains the joined json arrays as inet)</p>
  <p>How do I make this work so I can have every ip from the ips table returned which is either an ip in that addresses array or is part of a cidr in the ranges array?</p>