Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON field is string #44

Open
bitrut opened this issue Aug 16, 2017 · 7 comments
Open

JSON field is string #44

bitrut opened this issue Aug 16, 2017 · 7 comments
Labels

Comments

@bitrut
Copy link

bitrut commented Aug 16, 2017

Having field defined this way Column('abc', JSON), I have to use json.loads to get dict:

rows = await pg.fetch(sql)
async for row in rows:
    print(json.loads(row.abc))

row.abc is string

@nhumrich
Copy link
Contributor

Yes. That is correct. It might be considered premature to json load a json field that you might or might not want into a dict. Also, you might want to use ujson or something faster than standard json module.

That being said, I am not opposed to json being automatically loaded, maybe with a flag in the pool object? Your welcome to write a pull request that will implement this feature.

@jared-mackey
Copy link
Contributor

jared-mackey commented Aug 17, 2017

I believe loading JSON to be a feature of the ORM. Looking at the readme of this project it seems to only support SA core and not the ORM. The docs for SA mention you can specify json_serializer and json_deserializer functions in the call to create_engine. I believe all that would need to be done is to create an engine interface for the ORM and you would be able to load the objects from the JSON automatically.

It is possible to do it automatically in here but I am not sure if that would cause compatibility issues later when integrating with the ORM.

@achimnol
Copy link
Contributor

This issue is analogous to #45 .

@pierec
Copy link

pierec commented Oct 12, 2017

Hi! 0.18 changelog says that:

(...) In that case, it will actuall json dumps and loads automatically for you, which will break if you did it manually in your own code.

but I can't seem to get that to work like that with the default dialect settings. Is there something extra that needs to be done to get JSON auto-loaded and auto-dumped?

@nhumrich
Copy link
Contributor

hmm, this might not actually work... I will need to circle back on that.

@nhumrich nhumrich added the bug label Oct 24, 2017
@kamikaze
Copy link
Contributor

any news on this?

@nhumrich
Copy link
Contributor

This is a bug, that requires a lot more work to get working. For now you'll just have to json decode json feilds I guess. Pr's welcome ;)

I was premature in saying json decoding will work for you in the release notes. I misunderstood some things.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants