Skip to main content

De-/serialize Python dataclasses to or from JSON payloads. Compatible with Python 3.7 and newer.

Project description

databind.json

The databind.json package implements the de-/serialization to or from JSON payloads using the databind.core framework.

Check out the Documentation for examples.

Built-in converters

The following tables shows which types can be deserialized from / serialize to Python types with the native converters provided by the databind.json module:

Converter name Types Description
AnyConverter typing.Any Accept any value (useful for arbitrary JSON).
CollectionConverter typing.Collection[T], excl. str, bytes, bytearray, memoryview and typing.Mapping[K, V] Converts between native Python collections and JSON arrays.
DatetimeConverter datetime.date, datetime.datetime, datetime.time Converts between strings and date/time formats, using ISO 8601 time format by default (can be changed with the databind.core.settings.DateFormat setting).
DecimalConverter decimal.Decimal Converts between strings (and ints/floats if strict mode is off, strict mode is on by default) and decimals. The precision can be controlled with the databind.core.settings.Precision setting.
EnumConverter enum.Enum, enum.IntEnum Convert between strings and Python enumerations. The serialized form of IntEnum is the integer value, whereas the serialized form of Enum is a string (name of the enumeration value).
MappingConverter typing.Mapping[K, V] Converts between Python dicts and JSON objects. (While in theory K can be any type, for JSON K always needs to be str).
OptionalConverter typing.Optional[T] Handles optional fields in a schema.
PlainDatatypeConverter bytes, str, int, float, bool Converts between plain datatypes. In non-strict mode (off by default), numeric types will also accept strings as input for the deserialization.
SchemaConverter dataclasses.dataclass, typing.TypedDict Converts between Python dataclasses or typed dictionary and JSON objects.
UnionConverter typing.Union[...] Handles union types. Unions in JSON can be expressed in a multitide of ways, e.g. using a discriminator key and flat, keyed or nested structure or "best match". Check out the examples section of the documentation for more information.
LiteralConverter typing.Literal[...] Accepts or rejects a value based on whether it matches one of the values in the literal type hint.

The following converters are provided for convenience:

Converter name Types Description
StringifyConverter n/a A helper that allows to easily create de/serializers from a "to string" and "from string" function.

The following additional types are natively supported by databind.json using StringifyConverter:

Types Description
uuid.UUID Convert between strings and UUIDs.
pathlib.Path Convert between strings and paths.
pathlib.PurePath Convert between strings and paths.
nr.date.duration Deserialize from ISO 8601 duration strings or the object form, serialize to ISO 8601 strings.

Copyright © 2020 – Niklas Rosenstein

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

databind.json-4.2.6.tar.gz (13.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

databind.json-4.2.6-py3-none-any.whl (12.8 kB view details)

Uploaded Python 3

File details

Details for the file databind.json-4.2.6.tar.gz.

File metadata

  • Download URL: databind.json-4.2.6.tar.gz
  • Upload date:
  • Size: 13.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.3 readme-renderer/37.3 requests/2.28.1 requests-toolbelt/0.10.1 urllib3/1.26.12 tqdm/4.64.1 importlib-metadata/5.0.0 keyring/23.11.0 rfc3986/2.0.0 colorama/0.4.6 CPython/3.10.11

File hashes

Hashes for databind.json-4.2.6.tar.gz
Algorithm Hash digest
SHA256 3a3830cae939ca23f7ed3e86207a383d80e19eb9f8f209040be8ece0251d4668
MD5 16009d6b438d288da0a61417b61d2043
BLAKE2b-256 85c132fe2d545a9e8435d6ba6f4a518291761660bbf46c9a76913befd1edd47d

See more details on using hashes here.

File details

Details for the file databind.json-4.2.6-py3-none-any.whl.

File metadata

  • Download URL: databind.json-4.2.6-py3-none-any.whl
  • Upload date:
  • Size: 12.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.3 readme-renderer/37.3 requests/2.28.1 requests-toolbelt/0.10.1 urllib3/1.26.12 tqdm/4.64.1 importlib-metadata/5.0.0 keyring/23.11.0 rfc3986/2.0.0 colorama/0.4.6 CPython/3.10.11

File hashes

Hashes for databind.json-4.2.6-py3-none-any.whl
Algorithm Hash digest
SHA256 83d25b8b9be67e8dc1ee0d516d8e73529e054813aa4fbd051fb458d09e9719d6
MD5 f120b80f416ba8ac920a903048268fe1
BLAKE2b-256 58e4879a82789c2e8839ba6600bb03ee2752eb2bea035465142f843b784316e5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page