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

Allow custom json encoder / decoder #714

Closed
samuelcolvin opened this issue Aug 5, 2019 · 7 comments
Closed

Allow custom json encoder / decoder #714

samuelcolvin opened this issue Aug 5, 2019 · 7 comments
Labels
Change
Milestone

Comments

@samuelcolvin
Copy link
Collaborator

samuelcolvin commented Aug 5, 2019

makes more sense, perhaps we could have dump_json and load_json attributes of Config which are then used in parse_json(), json() and schema_json() (and anywhere else we use encode/decode json that I've forgotten about).

Originally posted by @samuelcolvin in #599 (comment)

@samuelcolvin
Copy link
Collaborator Author

samuelcolvin commented Aug 5, 2019

as discussed in #599 @pablogamboa suggested allowing a custom JSON encoder / decoder library.

This would allow libraries like orjson to be used without making them explicit dependencies of pydantic.

The problem here is going to be how to deal with the default argument with standard lib json and orjson allow, but not ujson.

@samuelcolvin samuelcolvin added this to the Version 1 milestone Aug 5, 2019
@samuelcolvin
Copy link
Collaborator Author

samuelcolvin commented Aug 5, 2019

If this requires a breaking change it should be done with the bump to version 1.

@Bobronium
Copy link
Contributor

Bobronium commented Aug 5, 2019

Did you think about implementing something similar to @JrooTJunior done in https://github.com/aiogram/aiogram/blob/dev-2.x/aiogram/utils/json.py?

@samuelcolvin
Copy link
Collaborator Author

samuelcolvin commented Aug 5, 2019

I would prefer more like the json_serialize argument in aiohttp, so the end user is responsible for implementing a function that correct encodes or decodes JSON.

@JrooTJunior
Copy link

JrooTJunior commented Aug 5, 2019

Yes. json_serialize is more good way.

I want to remove this code from aiogram.

https://github.com/aiogram/aiogram/blob/dev-2.x/aiogram/utils/json.py

@samuelcolvin samuelcolvin added Change and removed feature request labels Aug 5, 2019
@dutradda
Copy link

dutradda commented Aug 22, 2019

@samuelcolvin
is anyone implementing this now?
If not, I want to implement this feature.

@samuelcolvin
Copy link
Collaborator Author

samuelcolvin commented Aug 24, 2019

No one has started this. PR very welcome.

samuelcolvin added a commit that referenced this issue Sep 20, 2019
andreshndz pushed a commit to cuenca-mx/pydantic that referenced this issue Jan 17, 2020
* custom json (d)encoders, fix pydantic#714

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

No branches or pull requests

4 participants