title: How do I take my JSON data and put it into a MySQL table with Python?
body: <p>I have a huge JSON file of a database of movies. I also have a MySQL database with a movies table. I currently have a python list with all the JSON data, but I am stuck on how is the best way to turn that list into data I can put into my MySQL table.
  TLDR: How do I turn my Python list in JSON object format into a executable structure for MySQL. Here is the Python code:</p>
  <pre><code>import mysql.connector
  import json
  
  mydb = mysql.connector.connect(
      host=&quot;localhost&quot;,
      user=&quot;root&quot;,
      passwd=&quot;&quot;,
      database=&quot;testdb&quot;
  )
  
  mycursor = mydb.cursor()
  
  sqlFormula = &quot;INSERT INTO movies (title, year, cast, genres) VALUES (%s, %s, %s, %s)&quot;
  
  with open('movies.json', encoding=&quot;utf8&quot;) as json_file:
      data = json.load(json_file)
  
  print(data)
  
  mycursor.execute(sqlFormula, data)
  
  mydb.commit()
  </code></pre>
  <p>And here is a snippet of the JSON movie file:</p>
  <pre><code>    &quot;title&quot;: &quot;The Haunting in Connecticut&quot;,
      &quot;year&quot;: 2009,
      &quot;cast&quot;: [
        &quot;Virginia Madsen&quot;,
        &quot;Kyle Gallner&quot;,
        &quot;Martin Donovan&quot;,
        &quot;Elias Koteas&quot;,
        &quot;Amanda Crew&quot;
      ],
      &quot;genres&quot;: [
        &quot;Horror&quot;
      ]
    },
    {
      &quot;title&quot;: &quot;He's Just Not That Into You&quot;,
      &quot;year&quot;: 2009,
      &quot;cast&quot;: [
        &quot;Ben Affleck&quot;,
        &quot;Jennifer Aniston&quot;,
        &quot;Drew Barrymore&quot;,
        &quot;Jennifer Connelly&quot;,
        &quot;Kevin Connelly&quot;,
        &quot;Bradley Cooper&quot;,
        &quot;Ginnifer Goodwin&quot;,
        &quot;Scarlett Johansson&quot;,
        &quot;Justin Long&quot;
      ],
      &quot;genres&quot;: [
        &quot;Romance&quot;,
        &quot;Comedy&quot;
      ]
    }
  </code></pre>
  <p>MySQL movie table has a column for each title, year, cast, and genre. I am new to python, but my first guess would be to iterate through the list and save each title, year, etc as a variable then put that into another list and put that into my mycursor.execute(sqlFormula, combined list). If that is a bad solution or impossible, I wouldn't know. But if there is a better solution that I just don't know please help.</p>