Closed
Description
Initial Checks
- I confirm that I'm using Pydantic V2
Description
Currently when dumping model to json, objects of type bool
are being serialised as integers in json. I think this is a bug because json natively supports booleans (true
/false
).
Example Code
class SomeModel(BaseModel):
value: StrictFloat | StrictInt | StrictBool
m = SomeModel(value=True)
# Passes
assert type(m.model_dump(mode="python")["value"]) is bool
# This will fail
assert type(m.model_dump(mode="json")["value"]) is bool, "didn't serialise as bool"
Python, Pydantic & OS Version
Python 3.11.4
Pydantic 2.1.1
Pydantic Core 2.4.0
Windows 10
Selected Assignee: @davidhewitt