title: Extract postcode from Google Maps API JSON using Google Refine
body: <p>I'm trying to use Google Refine to extract postcodes from Google Maps API JSON.</p>
  
  <p>I added a new column by fetching URLs:</p>
  
  <p><code>"http://maps.googleapis.com/maps/api/geocode/json?sensor=false&amp;address=" + escape(value, "url")</code></p>
  
  <p>Then the resulting JSON is as follows:</p>
  
  <pre><code>{ "results" : [ { "address_components" : [ { "long_name" : "44", "short_name" : "44", "types" : [ "street_number" ] }, { "long_name" : "Homer Street", "short_name" : "Homer St", "types" : [ "route" ] }, { "long_name" : "London", "short_name" : "London", "types" : [ "locality", "political" ] }, { "long_name" : "Greater London", "short_name" : "Gt Lon", "types" : [ "administrative_area_level_2", "political" ] }, { "long_name" : "United Kingdom", "short_name" : "GB", "types" : [ "country", "political" ] }, { "long_name" : "W1H 4NW", "short_name" : "W1H 4NW", "types" : [ "postal_code" ] }, { "long_name" : "London", "short_name" : "London", "types" : [ "postal_town" ] } ], "formatted_address" : "44 Homer Street, London, Greater London W1H 4NW, UK", "geometry" : { "location" : { "lat" : 51.51981750, "lng" : -0.16534040 }, "location_type" : "ROOFTOP", "viewport" : { "northeast" : { "lat" : 51.52116648029151, "lng" : -0.1639914197084980 }, "southwest" : { "lat" : 51.51846851970851, "lng" : -0.1666893802915020 } } }, "types" : [ "street_address" ] } ], "status" : "OK" }
  </code></pre>
  
  <p>After browsing through a few blogs to find the relevant code, I then tried transforming the column using this...</p>
  
  <pre><code>value.parseJson().results[0]["formatted_address"]
  </code></pre>
  
  <p>...which works great for the full address.</p>
  
  <p>The problem occurs when I try to extract the postcode. I tried fiddling around and got nowhere, then I downloaded JSONPad and pasted the JSON into a tree map to get the path:</p>
  
  <pre><code>value.parseJson().results[0]["address_components"][5]["long_name"]
  </code></pre>
  
  <p>The problem is that this extracts the postcode perfectly for some entries, and not so perfectly for others, where it extracts something else - town or country, for example.</p>
  
  <p>Changing the [5] to [6] seems to extract the postcodes for the other addresses, but is there a way to extract ONLY the postcode, regardless of where it falls in the structure?</p>
  
  <p>Any help much appreciated!</p>