Re: [flask] JSONify SQLAlchemy query result
- From:
- M Wanstall
- Date:
- 2011-08-19 @ 05:27
Never mind, I sorted it out, I didn't realise how picky jsonify was as
to what it can and can't serialize. I got around it by adding a custom
function to the model that serializes the query result as a Dict and I
pass that through to jsonify and it works a treat.
Although you were right too Peter, I also wasn't executing the query.
Thanks for the help! :-)
On Thu, Aug 18, 2011 at 6:07 PM, Peter Ward <peteraward@gmail.com> wrote:
> Hi,
> Have you tried calling .all() on your resultset to get a list of objects,
> and serialise that?
> If not, perhaps a short code snippet to demonstrate the problem would help?
>
> On 18 August 2011 15:01, M Wanstall <malcolm.wanstall.lists@gmail.com>
> wrote:
>>
>> Hi all,
>>
>> I've been trying to pass a SQLAlchemy query resultset back via JSON
>> but keep hitting the "flaskext.sqlalchemy.BaseQuery object at
>> 0x1035dbdd0> is not JSON serializable" error.
>>
>> I know there's been a similar thread about this which suggesting
>> serializing the entire resultset (eg jsonify(rating_list = ratings)
>> where ratings is the SLQAlchemy query result) but this is what I'm
>> doing and it's what's causing the error.
>>
>> Any suggestions? Am I going about this the wrong way?
>>
>> Thanks!
>
>
>
> --
> Peter Ward
> http://flowblok.id.au/
> BIT III, Sydney University
>