-- This file is intended to test Postgres JSON Path 
-- Write your JSON data in the WITH clause, 
--   and your path below (see examples)
-- Then run this file in psql (or copy/paste the contents)
-- This works in recent Postgres verions (12 or later)
WITH Jsondata AS (SELECT '
{
 "a1" : {"name": "Andersson", "choices":[ 
            {"code":"MPSOF","meritScore":750},
            {"code":"MPALG","meritScore":750},
            {"code":"MPCSN","meritScore":800}
    ]},
 "a2" : {"name": "Jonsson", "choices" : [ 
            {"code":"MPALG","meritScore":700}
            ]},
 "a3" : {"name": "Larsson", "choices" : [ 
            {"code":"MPCSN","meritScore":850},
            {"code":"MPALG","meritScore":850}
            ]}
}
    ' :: JSONB AS jsondata)

SELECT jsonb_path_query(jsondata, 
    -- 'strict $.**.meritScore'
    'strict $.**?(@.choices[0].meritScore > 800).name'
  ) 
  FROM Jsondata;