-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Different output of V2 model_dump_json
compared to V1 json
#9019
Comments
Thanks for reporting this! Indeed, this is a V1 -> V2 change that hasn't yet been well documented. This is due to how serde json serialization works in This might help you as a workaround in the meantime: #8825. |
I've also marked this with a documentation tag, and will open a PR later this week to update the migration guide with a note on this change :). |
@sydney-runkle , thanks for the update. Solution suggested in #8825 can indeed help, but won't work if your pydantic objects contains types that import json
from datetime import datetime
from pydantic import BaseModel as BaseModel
class Message(BaseModel):
text: str
date: datetime
message = Message(text="¿Cómo estás?", date=datetime.now())
print(json.dumps(message.model_dump(), ensure_ascii=True))
# TypeError: Object of type datetime is not JSON serializable The runtime flag/config setting that you mentioned would be a great addition. Cheers. |
You can use |
Initial Checks
Description
When I read V2 migration guide, I did not expect major changes to how
model_dump_json
will work compared to V1'sjson
. However, it seems like there's a difference in how the new method handles non-ASCII characters.Is this expected behaviour?
Attached code produces different results for V2 and V1
Example Code
Python, Pydantic & OS Version
The text was updated successfully, but these errors were encountered: