Postgres: flatten Key-Value (K-V) store with jsonb_agg
You need a two step aggregation:

select bar_id, 
       jsonb_object_agg(externalidentifier, internals) as mappings
from (       
  SELECT foos.bar_id,
         externalidentifier, 
         jsonb_agg(internalIdentifier) as internals
  FROM foos
  GROUP BY bar_id, externalidentifier
) t
group by bar_id;


Your updated fiddle: https://www.db-fiddle.com/f/pKbFeRedD59s4f3VTnuyih/0