title: Convert array of arrays to json in Python
body: <p>I have an array of arrays which I get from a database query using <em>SQLAlchemy</em> and I want to do two things.</p>
  
  <ul>
  <li>I want to get the name of the columns (or something like <em>SELECT fullname AS "name n' surname" from table</em>).</li>
  <li>I want to convert the final product to a json array of objects, so that I can use it on the front-end.</li>
  </ul>
  
  <p>I have searched several hours and couldn't find an answer that works for my case.</p>
  
  <p>Here is the line of code querying the database and storing it in <em>results</em> variable:</p>
  
  <pre><code>results = session.query(categories.categoryname, products.pack, products.price, products.checkstate).join(products).all()
  </code></pre>
  
  <p>Here is the output of <code>print(results)</code>:</p>
  
  <blockquote>
    <p>[('chocolate', '3', 5, False), ('chocolate', '5', 7, False), ('chocolate', '10', 10, False), ('honey', '3', 5, False), ('honey', '5', 7, False), ('honey', '10', 10, False), ('candy', '3', 5, False), ('candy', '5', 7, False), ('candy', '10', 10, False)]</p>
  </blockquote>
  
  <p>If I use <code>json.dump(results)</code> I get this:</p>
  
  <blockquote>
    <p>[["chocolate", "3", 5, false], ["chocolate", "5", 7, false], ["chocolate", "10", 10, false], ["honey", "3", 5, false], ["honey", "5", 7, false], ["honey", "10", 10, false], ["candy", "3", 5, false], ["candy", "5", 7, false], ["candy", "10", 10, false]]</p>
  </blockquote>
  
  <p>Now to be more specific, what I'm trying to end up with is this:</p>
  
  <blockquote>
    <p>[{"type": "chocolate", "pack": "3", "price": 5, "checkstate": false}, ....etc... ]</p>
  </blockquote>