PostgreSQL - Flatten nested JSONB object array
Set returning functions should be called in the FROM.
SELECT mt.measurement_id,
       p.port -&gt;&gt; 'port_name' as &quot;port_name&quot;,
       p.port -&gt;&gt; 'port_description' as &quot;port_description&quot;,
       p.port -&gt;&gt; 'port_status_int' as &quot;port_status_int&quot;,
       p.port -&gt;&gt; 'port_status' as &quot;port_status&quot;,
       p.port -&gt;&gt; 'port_speed_int' as &quot;port_speed_int&quot;,
       p.port -&gt;&gt; 'ports_speed' as &quot;ports_speed&quot;
from mytable mt 
  cross join jsonb_array_elements(mt.data-&gt;'ports') as p(port)
where device_id = 20;

You can simplify this a bit, by using jsonb_to_recordset:
SELECT  mt.measurement_id,
        p.*
from mytable mt 
  cross join jsonb_to_recordset(mt.data-&gt;'ports') as p(port_name text, port_description text, port_status_int int, port_status text, port_speed_int int, ports_speed text) 
where device_id = 20;