OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

How to serialize SqlAlchemy result to JSON?

  • Thread starter Thread starter Zelid
  • Start date Start date
Z

Zelid

Guest
Django has some good automatic serialization of ORM models returned from DB to JSON format.

How to serialize SQLAlchemy query result to JSON format?

I tried jsonpickle.encode but it encodes query object itself. I tried json.dumps(items) but it returns

Code:
TypeError: <Product('3', 'some name', 'some desc')> is not JSON serializable

Is it really so hard to serialize SQLAlchemy ORM objects to JSON /XML? Isn't there any default serializer for it? It's very common task to serialize ORM query results nowadays.

What I need is just to return JSON or XML data representation of SQLAlchemy query result.

SQLAlchemy objects query result in JSON/XML format is needed to be used in javascript datagird (JQGrid http://www.trirand.com/blog/)
<p>Django has some good automatic serialization of ORM models returned from DB to JSON format.</p>

<p>How to serialize SQLAlchemy query result to JSON format? </p>

<p>I tried <code>jsonpickle.encode</code> but it encodes query object itself.
I tried <code>json.dumps(items)</code> but it returns</p>

<pre><code>TypeError: <Product('3', 'some name', 'some desc')> is not JSON serializable
</code></pre>

<p>Is it really so hard to serialize SQLAlchemy ORM objects to JSON /XML? Isn't there any default serializer for it? It's very common task to serialize ORM query results nowadays.</p>

<p>What I need is just to return JSON or XML data representation of SQLAlchemy query result.</p>

<p>SQLAlchemy objects query result in JSON/XML format is needed to be used in javascript datagird (JQGrid <a href="http://www.trirand.com/blog/" rel="noreferrer">http://www.trirand.com/blog/</a>)</p>
 

Latest posts

Top