title: How to convert bulk of csv into json
body: <p>Below is the code to convert one csv file into json</p>
  <p>List all the files in the dir</p>
  <p>[data1.csv, data2.csv,data.csv]</p>
  <p>Below is the code to convert one file to json. Like i need to loop all the files</p>
  <pre><code>import csv 
  import json 
  import os
  import glob
  
  os.chdir(r'dir' )
  result = glob.glob( '*.csv' )
  print (result) 
  def make_json(csvFilePath, jsonFilePath): 
        
      for i in result:
          data = {} 
          with open(csvFilePath, encoding='utf-8') as csvf: 
              csvReader = csv.DictReader(csvf) 
              for rows in csvReader: 
                  key = rows['id'] 
                  data[key] = rows 
          with open(jsonFilePath, 'w', encoding='utf-8') as jsonf: 
              jsonf.write(json.dumps(data, indent=4)) 
          csvFilePath =f&quot;{i}&quot;
          jsonFilePath =f&quot;{i.split('.')[-2]}.json&quot;
  make_json(csvFilePath, jsonFilePath)
  </code></pre>
  <p>I have similar kind of files which need to convert into json. in every files <code>id</code> is the primary key</p>
  <p>Lot of files are there. i dont want to change the csvFilePath and jsonFilePath  everytime.</p>
  <p>The issue facing?</p>
  <ul>
  <li>My all json files is ending with <code>.csv.json</code></li>
  <li>Last file name data9.csv is not converting to json and data2 is converting twice as data2.json and data2.csv.json</li>
  </ul>