title: How to convert multiple json files to cvs files
body: <p>Hello I have multiple json files in a path and I want to convert all of them to csv files separately. Here is what I have tried so far which just convert one json file to a csv file.</p>
  <pre><code>with open('/Users/hh/MyDataSet/traceJSON-663-661-A0-25449-7.json') as f:
    for line in f:
       data.append(json.loads(line))
  
  csv_file=open('/Users/hh/MyDataSet/GTruth/traceJSON-663-661-A0-25449-7.csv','w')
  
  write=csv.writer(csv_file)
  # write.writerow([&quot;row number&quot;,&quot;type&quot;,&quot;rcvTime&quot;,&quot;pos_x&quot;,&quot;pos_y&quot;,&quot;pos_z&quot;,&quot;spd_x&quot;,&quot;spd_y&quot;,&quot;spd_z&quot;,&quot;acl_x&quot;,&quot;acl_y&quot;,&quot;acl_z&quot;
  #                 ,&quot;hed_x&quot;,&quot;hed_y&quot;,&quot;hed_z&quot;])
  write.writerow([&quot;row number&quot;,&quot;type&quot;,&quot;rcvTime&quot;,&quot;sender&quot;,&quot;pos_x&quot;,&quot;pos_y&quot;,&quot;pos_z&quot;,&quot;spd_x&quot;,&quot;spd_y&quot;,&quot;spd_z&quot;,&quot;acl_x&quot;,&quot;acl_y&quot;,&quot;acl_z&quot;
                  ,&quot;hed_x&quot;,&quot;hed_y&quot;,&quot;hed_z&quot;])
  for elem in range(len(data)):    
     if data[elem]['type']==2:
       write.writerow([elem,data[elem]['type'],round(data[elem]['rcvTime'],2),'663',round(data[elem]['pos'][0],2),round(data[elem]['pos'][1],2)
                     ,round(data[elem]['pos'][2],2),round(data[elem]['spd'][0],2),round(data[elem]['spd'][1],2),round(data[elem]['spd'][2],2),
                     round(data[elem]['acl'][0],2),round(data[elem]['acl'][1],2),round(data[elem]['acl'][2],2),round(data[elem]['hed'][0],2),
                    round(data[elem]['hed'][1],2),round(data[elem]['hed'][2],2)])
     elif data[elem]['type']==3:
       write.writerow([elem,data[elem]['type'],round(data[elem]['rcvTime'],2),round(data[elem]['sender'],2),round(data[elem]['pos'][0],2),round(data[elem]['pos'][1],2)
                     ,round(data[elem]['pos'][2],2),round(data[elem]['spd'][0],2),round(data[elem]['spd'][1],2),round(data[elem]['spd'][2],2),
                     round(data[elem]['acl'][0],2),round(data[elem]['acl'][1],2),round(data[elem]['acl'][2],2),round(data[elem]['hed'][0],2),
                    round(data[elem]['hed'][1],2),round(data[elem]['hed'][2],2)])
  # json_file.close()
  print('done!')
  csv_file.close()
  </code></pre>
  <p>I appreciate if anyone can help me how can I do it. Also in each json file name &quot;traceJSON-663-661-A0-25449-7&quot;, the first number like in the above code (663) should be written in csv file like the following code,if the type is 2:</p>
  <pre><code>write.writerow([elem,data[elem]['type'],round(data[elem]['rcvTime'],2),'663',....
  </code></pre>
  <p>My json file names are like traceJSON-51-49-A16-25217-7, traceJSON-57-55-A0-25223-7, ....</p>