title: How to convert CSV to JSON?
body: <p>I have a CSV file with the header as Key and the data as the Value. My goal is to convert the CSV file into Json to upload into a database and output the data I uploaded. I have successfully converted the CSV into Json,but I am having trouble with my output.</p>
  
  <p>What I currently have</p>
  
  <pre><code>import csv
  import json
  import pandas as pd
  csvfile = open ('so-emissions-by-world-region-in-million-tonnes.csv','r')
  reader = csv.DictReader(csvfile)
  result = []
  for row in reader:
      result.append(row)
  result = json.dumps(result)
  result = json.loads(result)
  keys = ('Entity' ,'Year','SO2 emissions- Clio Infra')
  print(result)
  </code></pre>
  
  <p>CSV Data:</p>
  
  <pre class="lang-none prettyprint-override"><code>[{'502 emissions- Clio Infra': '0', 'Entity': 'Africa', 'Year': '1860 '},
   {'502 emissions- Clio Infra': '0', 'Entity': 'Africa', 'Year': '1870'},
   {'502 emissions- Clio Infra': '0.059', 'Entity': 'Africa', 'Year': '1880'},
   {'502 emissions- Clio Infra': '0.065', 'Entity': 'Africa', 'Year': '1890'},
   {'502 emissions- Clio Infra': '0.071', 'Entity': 'Africa', 'Year': ' 1900'},
   {'502 emissions- Clio Infra': '0.146', 'Entity': 'Africa', 'Year': '1910'},
   {'502 emissions- Clio Infra': '0.372', 'Entity': 'Africa', 'Year': '1920'},
   {'502 emissions- Clio Infra': '0.41', 'Entity': 'Africa', 'Year': ' 1930'},
   {'502 emissions- Clio Infra': '0.56 ', 'Entity': 'Africa', 'Year ': '1940'}]
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/qQ8tO.png" rel="nofollow noreferrer">This is the output of result</a></p>
  
  <p>Correct output:</p>
  
  <pre class="lang-none prettyprint-override"><code>'First Key'
  Value 1
  Value 2
  Value 3
  ...
  'Second Key'
  Value 1
  Value 2
  Value 3
  ...
  'Third Key'
  Value 1
  Value 2
  Value 3
  ...
  </code></pre>