title: Flattening nested JSON API dictionaries in Python
body: <p>I am receiving the following json response for a distances matrix which was gathered using the following code:</p>
  <pre><code>import requests
  import json
  
  payload = {
      &quot;origins&quot;: [{&quot;latitude&quot;: 54.6565153, &quot;longitude&quot;: -1.6802816}, {&quot;latitude&quot;: 54.6365153, &quot;longitude&quot;: -1.6202816}], #surgery
      &quot;destinations&quot;: [{&quot;latitude&quot;: 54.6856522, &quot;longitude&quot;: -1.2183634}, {&quot;latitude&quot;: 54.5393295, &quot;longitude&quot;: -1.2623914}, {&quot;latitude&quot;: 54.5393295, &quot;longitude&quot;: -1.2623914}], #oa - up to 625 entries
      &quot;travelMode&quot;: &quot;driving&quot;,
      &quot;startTime&quot;: &quot;2014-04-01T11:59:59+01:00&quot;,
      &quot;timeUnit&quot;: &quot;second&quot;
  }
  headers = {&quot;Content-Length&quot;: &quot;497&quot;, &quot;Content-Type&quot;: &quot;application/json&quot;}
  paramtr = {&quot;key&quot;: &quot;INSERT_KEY_HERE&quot;}
  r = requests.post('https://dev.virtualearth.net/REST/v1/Routes/DistanceMatrix', data = json.dumps(payload), params = paramtr, headers = headers)
  data = r.json()[&quot;resourceSets&quot;][0][&quot;resources&quot;][0]
  </code></pre>
  <p>and am attempting to flatten:</p>
  <blockquote>
  <p>destinations.latitude, destinations.longitude, origins.latitude,
  origins.longitude, departureTime, destinationIndex, originIndex,
  totalWalkDuration, travelDistance, travelDuration</p>
  </blockquote>
  <p>from:</p>
  <pre><code>    {'__type': 'DistanceMatrix:http://schemas.microsoft.com/search/local/ws/rest/v1',
   'destinations': [{'latitude': 54.6856522, 'longitude': -1.2183634},
    {'latitude': 54.5393295, 'longitude': -1.2623914},
    {'latitude': 54.5393295, 'longitude': -1.2623914}],
   'errorMessage': 'Request completed.',
   'origins': [{'latitude': 54.6565153, 'longitude': -1.6802816},
    {'latitude': 54.6365153, 'longitude': -1.6202816}],
   'results': [{'departureTime': '/Date(1396349159000-0700)/',
     'destinationIndex': 0,
     'originIndex': 0,
     'totalWalkDuration': 0,
     'travelDistance': 38.209,
     'travelDuration': 3082},
    {'departureTime': '/Date(1396349159000-0700)/',
     'destinationIndex': 1,
     'originIndex': 0,
     'totalWalkDuration': 0,
     'travelDistance': 40.247,
     'travelDuration': 2708},
    {'departureTime': '/Date(1396349159000-0700)/',
     'destinationIndex': 2,
     'originIndex': 0,
     'totalWalkDuration': 0,
     'travelDistance': 40.247,
     'travelDuration': 2708},
    {'departureTime': '/Date(1396349159000-0700)/',
     'destinationIndex': 0,
     'originIndex': 1,
     'totalWalkDuration': 0,
     'travelDistance': 34.857,
     'travelDuration': 2745},
    {'departureTime': '/Date(1396349159000-0700)/',
     'destinationIndex': 1,
     'originIndex': 1,
     'totalWalkDuration': 0,
     'travelDistance': 36.895,
     'travelDuration': 2377},
    {'departureTime': '/Date(1396349159000-0700)/',
     'destinationIndex': 2,
     'originIndex': 1,
     'totalWalkDuration': 0,
     'travelDistance': 36.895,
     'travelDuration': 2377}]}
  </code></pre>
  <p>The best I have currently achieved is:</p>
  <pre><code>json_normalize(outtie, record_path=&quot;results&quot;, meta=&quot;origins&quot;)
  </code></pre>
  <p>However this contains nested origins and destinations refuse to append. I also tried to drop the type to see if it made a difference, and explored max_level= and record_prefix='_' but to no avail.</p>