title: Retrieve data from SQL Server and convert it into JSON using python
body: <p>I'm trying to retrieve data from SQL server database and convert into JSON format using python script but I'm getting some errors.  </p>
  
  <p>Here is my code: </p>
  
  <pre><code>import pyodbc
      import json
      conn = pyodbc.connect('Driver={SQL Server};'
                            'Server=localhost;'
                            'Database=TestDB;'
                            'Trusted_Connection=yes;')
  
      cursor = conn.cursor()
      cursor.execute('select * from dbo.test where id = 1 ')
      rs = cursor.fetchall()
      result = dict(rs)
      r = json.dumps(rs)
      for row in r:
           print(r)
  </code></pre>
  
  <p>Error: </p>
  
  <blockquote>
    <p>result = dict(rs)<br>
     ValueError: dictionary update sequence element #0 has length 6; 2 is required</p>
  </blockquote>
  
  <p>Expected output:</p>
  
  <pre><code>"{ "id" : 1, "type": "release",  "consent": true,  "quantity": 5}" 
  </code></pre>
  
  <p>Please let me know where I'm wrong in my script.</p>