Skip to content

Conversion Table

The following table provides details on how Pydantic converts data during validation in both strict and lax modes.

The “Strict” column contains checkmarks for type conversions that are allowed when validating in Strict Mode.

Field TypeInputStrictInput SourceConditions
boolbool✓Python & JSON
boolfloatPython & JSONAllowed values: 0.0, 1.0.
boolintPython & JSONAllowed values: 0, 1.
boolstrPython & JSONAllowed values: 'f', 'n', 'no', 'off', 'false', 'False', 't', 'y', 'on', 'yes', 'true', 'True'.
boolDecimalPythonAllowed values: Decimal(0), Decimal(1).
bytesbytearrayPython
bytesbytes✓Python
bytesstr✓JSON
bytesstrPython
callable-JSONNever valid.
callableAny✓Pythoncallable() check must return True.
datebytesPythonFormat: YYYY-MM-DD (UTF-8).
datedate✓Python
datedatetimePythonMust be exact date, eg. no H, M, S, f.
datefloatPython & JSONInterpreted as seconds or ms from epoch. See speedate. Must be exact date.
dateintPython & JSONInterpreted as seconds or ms from epoch. See speedate. Must be exact date.
datestrPython & JSONFormat: YYYY-MM-DD.
dateDecimalPythonInterpreted as seconds or ms from epoch. See speedate. Must be exact date.
datetimebytesPythonFormat: YYYY-MM-DDTHH:MM:SS.f or YYYY-MM-DD. See speedate, (UTF-8).
datetimedatePython
datetimedatetime✓Python
datetimefloatPython & JSONInterpreted as seconds or ms from epoch, see speedate.
datetimeintPython & JSONInterpreted as seconds or ms from epoch, see speedate.
datetimestrPython & JSONFormat: YYYY-MM-DDTHH:MM:SS.f or YYYY-MM-DD. See speedate.
datetimeDecimalPythonInterpreted as seconds or ms from epoch, see speedate.
dequedeque✓Python
dequefrozensetPython
dequelistPython
dequesetPython
dequetuplePython
dequeArray✓JSON
dictdict✓Python
dictMappingPythonMust implement the mapping interface and have an items() method.
dictObject✓JSON
floatboolPython & JSON
floatbytesPythonMust match [0-9]+(\.[0-9]+)?.
floatfloat✓Python & JSONbool is explicitly forbidden.
floatint✓Python & JSON
floatstrPython & JSONMust match [0-9]+(\.[0-9]+)?.
floatDecimalPython
frozensetdequePython
frozensetdict_keysPython
frozensetdict_valuesPython
frozensetfrozenset✓Python
frozensetlistPython
frozensetsetPython
frozensettuplePython
frozensetArray✓JSON
intboolPython & JSON
intbytesPythonMust be numeric only, e.g. [0-9]+.
intfloatPython & JSONMust be exact int, e.g. val % 1 == 0, raises error for nan, inf.
intint✓Python & JSONbool is explicitly forbidden.
intintPython & JSON
intstrPython & JSONMust be numeric only, e.g. [0-9]+.
intDecimalPythonMust be exact int, e.g. val % 1 == 0.
listdequePython
listdict_keysPython
listdict_valuesPython
listfrozensetPython
listlist✓Python
listsetPython
listtuplePython
listArray✓JSON
namedtupledict✓Python
namedtuplelist✓Python
namedtuplenamedtuple✓Python
namedtupletuple✓Python
namedtupleArray✓JSON
namedtupleNamedTuple✓Python
setdequePython
setdict_keysPython
setdict_valuesPython
setfrozensetPython
setlistPython
setset✓Python
settuplePython
setArray✓JSON
strbytearrayPythonAssumes UTF-8, error on unicode decoding error.
strbytesPythonAssumes UTF-8, error on unicode decoding error.
strstr✓Python & JSON
timebytesPythonFormat: HH:MM:SS.FFFFFF. See speedate.
timefloatPython & JSONInterpreted as seconds, range 0 - 86399.9*.
timeintPython & JSONInterpreted as seconds, range 0 - 86399.
timestrPython & JSONFormat: HH:MM:SS.FFFFFF. See speedate.
timetime✓Python
timeDecimalPythonInterpreted as seconds, range 0 - 86399.9*.
timedeltabytesPythonFormat: ISO8601. See speedate, (UTF-8).
timedeltafloatPython & JSONInterpreted as seconds.
timedeltaintPython & JSONInterpreted as seconds.
timedeltastrPython & JSONFormat: ISO8601. See speedate.
timedeltatimedelta✓Python
timedeltaDecimalPythonInterpreted as seconds.
tupledequePython
tupledict_keysPython
tupledict_valuesPython
tuplefrozensetPython
tuplelistPython
tuplesetPython
tupletuple✓Python
tupleArray✓JSON
typetype✓Python
AnyAny✓Python & JSON
ByteSizefloat✓Python & JSON
ByteSizeint✓Python & JSON
ByteSizestr✓Python & JSON
ByteSizeDecimal✓Python
Decimalfloat✓JSON
DecimalfloatPython & JSON
Decimalint✓JSON
DecimalintPython & JSON
Decimalstr✓JSON
DecimalstrPython & JSONMust match [0-9]+(\.[0-9]+)?.
DecimalDecimal✓Python
EnumAny✓JSONInput value must be convertible to enum values.
EnumAnyPythonInput value must be convertible to enum values.
EnumEnum✓Python
IPv4AddressbytesPython
IPv4AddressintPythoninteger representing the IP address, must be less than 2**32
IPv4Addressstr✓JSON
IPv4AddressstrPython & JSON
IPv4AddressIPv4Address✓Python
IPv4AddressIPv4Interface✓Python
IPv4InterfacebytesPython
IPv4InterfaceintPythoninteger representing the IP address, must be less than 2**32
IPv4Interfacestr✓JSON
IPv4InterfacestrPython & JSON
IPv4InterfacetuplePython
IPv4InterfaceIPv4AddressPython
IPv4InterfaceIPv4Interface✓Python
IPv4NetworkbytesPython
IPv4NetworkintPythoninteger representing the IP network, must be less than 2**32
IPv4Networkstr✓JSON
IPv4NetworkstrPython & JSON
IPv4NetworkIPv4AddressPython
IPv4NetworkIPv4InterfacePython
IPv4NetworkIPv4Network✓Python
IPv6AddressbytesPython
IPv6AddressintPythoninteger representing the IP address, must be less than 2**128
IPv6Addressstr✓JSON
IPv6AddressstrPython & JSON
IPv6AddressIPv6Address✓Python
IPv6AddressIPv6Interface✓Python
IPv6InterfacebytesPython
IPv6InterfaceintPythoninteger representing the IP address, must be less than 2**128
IPv6Interfacestr✓JSON
IPv6InterfacestrPython & JSON
IPv6InterfacetuplePython
IPv6InterfaceIPv6AddressPython
IPv6InterfaceIPv6Interface✓Python
IPv6NetworkbytesPython
IPv6NetworkintPythoninteger representing the IP address, must be less than 2**128
IPv6Networkstr✓JSON
IPv6NetworkstrPython & JSON
IPv6NetworkIPv6AddressPython
IPv6NetworkIPv6InterfacePython
IPv6NetworkIPv6Network✓Python
InstanceOf-JSONNever valid.
InstanceOfAny✓Pythonisinstance() check must return True.
IntEnumAny✓JSONInput value must be convertible to enum values.
IntEnumAnyPythonInput value must be convertible to enum values.
IntEnumIntEnum✓Python
Iterabledeque✓Python
Iterablefrozenset✓Python
Iterablelist✓Python
Iterableset✓Python
Iterabletuple✓Python
IterableArray✓JSON
NamedTupledict✓Python
NamedTuplelist✓Python
NamedTuplenamedtuple✓Python
NamedTupletuple✓Python
NamedTupleArray✓JSON
NamedTupleNamedTuple✓Python
NoneNone✓Python & JSON
Pathstr✓JSON
PathstrPython
PathPath✓Python
Patternbytes✓PythonInput must be a valid pattern.
Patternstr✓Python & JSONInput must be a valid pattern.
SequencedequePython
Sequencelist✓Python
SequencetuplePython
SequenceArray✓JSON
TypedDictdict✓Python
TypedDictAny✓Python
TypedDictMappingPythonMust implement the mapping interface and have an items() method.
TypedDictObject✓JSON
UUIDstr✓JSON
UUIDstrPython
UUIDUUID✓Python