title: How to convert csv to json in python?
body: <p>I'm very new to programming, have been learning python from past 3/4 weeks and
  this is one of the assignments given.</p>
  
  <p>Input</p>
  
  <pre class="lang-none prettyprint-override"><code>A, B, C, D
  1, 2, 3, 4
  5, 6, 7, 8
  </code></pre>
  
  <p>Output</p>
  
  <pre class="lang-none prettyprint-override"><code>{{A:"1", B:"2", C:"3", D:"4"}, {A:"5", B:"6", C:"7", D:"8"}}
  </code></pre>
  
  <p>I've been trying with the code as:</p>
  
  <pre><code>import csv
  import json
  
  csvfile = open('test.csv','r')
  jsonfile = open('test.json','w')
  
  x = ("a","b","c","d")
  
  reader = csv.DictReader(csvfile, x)
  for row in reader:
      json.dump(row, jsonfile)
  </code></pre>
  
  <p>The output for this code comes as below:</p>
  
  <pre class="lang-none prettyprint-override"><code>{"a": "1", "null": ["5", "6", "7", "8", "9"], "c": "3", "b": "2", "d": "4"}
  </code></pre>
  
  <p>Can anyone help me on this?</p>