title: Convert a directory of JSON files to one CSV file with a Py loop
body: <p>I have a directory with hundreds of JSON files, and would like to convert and merge them into one CSV file.</p>
  <p>I found <a href="https://stackoverflow.com/questions/1871524/how-can-i-convert-json-to-csv">this</a> question. One answer explains how to convert one JSON file to CSV:</p>
  <pre><code>import pandas as pd
  with open('jsonfile.json', encoding='utf-8') as inputfile:
      df = pd.read_json(inputfile)
  df.to_csv('csvfile.csv', encoding='utf-8', index=False)
  </code></pre>
  <p>Using that code, I tried to create a loop, but I can't make it work (I'm new to programming). This is what I tried:</p>
  <pre><code>import pandas as pd
  import os
  dir1 = 'jsfiles'
  fileList = os.listdir(dir1)
  for ffile in fileList:
      with open(ffile, encoding='utf-8') as inputfile:
          df = pd.read_json(inputfile)
  df.to_csv('csvfile.csv', encoding='utf-8', index=False)
  </code></pre>
  <p>I get this error:</p>
  <pre><code>ValueError: Trailing data
  </code></pre>