title: How to insert nested dictionary/json into MySQL table with Python
body: <p>I've connected to the <a href="https://exchangeratesapi.io/" rel="nofollow noreferrer">https://exchangeratesapi.io/</a> api like so:</p>
  
  <pre><code>import requests, json, pymysql
  from db_credentials import db_config
  
  get_url = "https://api.exchangeratesapi.io/history?start_at=2018-01-01&amp;end_at=2018-02-02&amp;base=GBP"
  response = requests.get(get_url)
  results = response.content
  data = json.loads(results.decode('utf-8'))['rates']
  
  print(data.keys())
  print(data)
  </code></pre>
  
  <p><code>data.keys()</code> and <code>data</code> looks like this:</p>
  
  <pre><code>dict_keys(['2018-01-22', '2018-01-09', '2018-01-24', '2018-01-03', '2018-01-23', '2018-01-25', '2018-01-18', '2018-02-02', '2018-01-15', '2018-01-02', '2018-01-16', '2018-01-11', '2018-01-17', '2018-01-12', '2018-01-30', '2018-02-01', '2018-01-29', '2018-01-08', '2018-01-10', '2018-01-05', '2018-01-04', '2018-01-26', '2018-01-31', '2018-01-19'])
  
  {'2018-01-02': {'AUD': 1.7327127809,
                  'BGN': 2.1986891954,
                  'BRL': 4.440996931,
                  'CAD': 1.7006733893,
                  ...},
   '2018-01-03': {'AUD': 1.730482852,
                  'BGN': 2.2064530686,
                  'BRL': 4.4264440433,
                  ...},
   ...}
  </code></pre>
  
  <p>I have an empty MySQL table with date, currency and rate columns which I'd like to populate with the above using something along the lines of the following code:</p>
  
  <pre><code>connection = pymysql.connect(**db_config, cursorclass=pymysql.cursors.DictCursor)
  with connection.cursor() as cursor:
      insert_statement = "INSERT INTO gbpExchangeRates VALUES (%s)" % data
      cursor.execute(insert_statement)
  connection.commit()
  connection.close()
  </code></pre>
  
  <p>Obviously it doesn't work and requires some manipulation beforehand...
  I tried <code>data = json.dumps(data)</code> but not sure what to do next...</p>