Python query SQLite map values to column names
<p>I am creating a python script to query a SQLite DB file. I have connected to the SQLite db file and ran the SELECT query to retrieve data.</p>

<p>The issue is that the output is missing the column names.</p>

<pre><code>import sqlite3 as lite
import sys
import json

con = lite.connect('example.db')

with con:

        con.row_factory = lite.Row

        cur = con.cursor()
        cur.execute("SELECT * FROM Devices")

        rows = cur.fetchall()

        rowarray_list = []
        for row in rows:
                t = (row['id'], row['name'], row['type'])
                rowarray_list.append(t)

        j = json.dumps(rowarray_list)
        rowarrays_file = 'rowarrays.js'
        f = open(rowarrays_file,'w')
        print (f, j)
</code></pre>

<p>Here is the output of the script.</p>

<pre><code>&lt;_io.TextIOWrapper name='rowarrays.js' mode='w' encoding='UTF-8'&gt; [[1, "example1", "Computer"], [2, "example2", "Server"], [3, "example3", "Server"]
</code></pre>

<p>Below is the output required.</p>

<pre><code>{"records":[{"id": "1", "name": "example1", "type": "Computer"}, {"id": "2", "name": "example2", "type": "Server"}, {"id": "3", "name": "example3", "type": "Server"}]}
</code></pre>