Google Refine: iterate over JSON dictionary

I have JSON in Google Refine - http://mapit.mysociety.org/point/4326/0.1293497,51.5464828 for the full version, but in abbreviated form it looks like this:

{1234: {'name': 'Barking', 'type': 'WMC'},
 5678: {'name': 'England', 'type': 'EUR'} }

I only want to extract the name for an object with a (supposedly unique) type WMC.

Parsing JSON in Google Refine doesn't help, which works with arrays, not dicts.

Any suggestions I should look at to fix this?


Change . I don’t know what the initial keys are: I believe that they are unique identifiers that I cannot predict in advance.

+5
source share
1 answer

Refine , dict, ( ).

JSON JSON. GREL , JSON, "WMC".

filter(('['+(value.replace(/"[0-9]+":/,""))[1,-1]+']').parseJson(),v,v['type']=='WMC')[0]['name']

" ", WMC. , , , forEach

forEach(filter(('['+(value.replace(/"[0-9]+":/,""))[1,-1]+']').parseJson(),v,v['type']=='WMC'),x,x['name']).join('|')

, , " ".

.

+4
source

All Articles