{"id":7135,"library":"databind-json","title":"databind-json","description":"The `databind-json` library (version 4.5.4) provided de-/serialization capabilities for Python dataclasses to and from JSON payloads, compatible with Python 3.8 and newer. This package is officially deprecated. Its core functionality has been integrated directly into the `databind` library, specifically within the `databind.json` module. While `databind-json` has received recent maintenance updates, new projects and existing users are strongly advised to migrate to the `databind` package for all serialization needs, benefiting from broader support and continued development.","status":"deprecated","version":"4.5.4","language":"en","source_language":"en","source_url":"https://github.com/NiklasRosenstein/python-databind","tags":["serialization","deserialization","json","dataclasses","deprecated"],"install":[{"cmd":"pip install databind-json","lang":"bash","label":"Install databind-json (Deprecated)"},{"cmd":"pip install databind","lang":"bash","label":"Install recommended replacement (databind)"}],"dependencies":[],"imports":[{"symbol":"dumps","correct":"from databind_json import dumps"},{"symbol":"loads","correct":"from databind_json import loads"}],"quickstart":{"code":"from dataclasses import dataclass\nfrom typing import Optional, Union\nfrom databind_json import dumps, loads\n\n@dataclass\nclass Address:\n    street: str\n    city: str\n\n@dataclass\nclass User:\n    id: int\n    name: str\n    email: Optional[str] = None\n    address: Optional[Address] = None\n\n# Serialize a User object\nuser = User(id=123, name=\"Alice Smith\", email=\"alice@example.com\", address=Address(street=\"123 Main St\", city=\"Anytown\"))\njson_payload = dumps(user)\nprint(\"Serialized JSON:\", json_payload)\n\n# Deserialize a JSON string back into a User object\njson_string_to_load = '{\"id\": 456, \"name\": \"Bob Johnson\", \"email\": null, \"address\": {\"street\": \"456 Oak Ave\", \"city\": \"Otherville\"}}'\ndeserialized_user = loads(json_string_to_load, User)\nprint(\"Deserialized User:\", deserialized_user)\n\n# Example with an optional field not present in JSON (deserializes to None)\njson_no_address = '{\"id\": 789, \"name\": \"Charlie Brown\"}'\nuser_no_address = loads(json_no_address, User)\nprint(\"User with no address in JSON:\", user_no_address)","lang":"python","description":"Demonstrates basic serialization and deserialization of dataclasses, including handling of `Optional` fields and nested dataclasses, using the `dumps` and `loads` functions from `databind_json`."},"warnings":[{"fix":"Migrate to the `databind` package. Install using `pip install databind` and update your import statements from `from databind_json import ...` to `from databind.json import ...`.","message":"The `databind-json` package is officially deprecated and is no longer the recommended library for JSON serialization of dataclasses. Its functionality has been fully integrated into the `databind` library under the `databind.json` module.","severity":"breaking","affected_versions":"All versions"},{"fix":"Ensure `Union` types are precisely defined (e.g., more specific types before less specific ones). For `Optional[T]`, use `Union[T, None]`. Upgrade to `databind-json` 4.5.4 (or `databind` 4.5.4) to benefit from recent fixes related to `RecursionError` and `Union` with `Literal` types. Refer to the `databind` documentation for best practices on complex type hints.","message":"Incorrect handling or complex definitions of `typing.Union` or `typing.Optional` types within dataclass fields can lead to unexpected serialization failures or `RecursionError`. This is especially relevant when `Union` types include `typing.Literal` values or when Union settings are inherited via MRO.","severity":"gotcha","affected_versions":"<4.5.4 (for RecursionError), <4.5.3 (for Union with Literal)"},{"fix":"Upgrade to `databind-json` 4.5.4 (or `databind` 4.5.4). Carefully review dataclass inheritance patterns involving generics, ensuring they are correctly instantiated or that field inference is unambiguous. Consult the `databind` documentation on class settings and inheritance for detailed guidance.","message":"Dataclasses inheriting from uninstantiated `typing.Generic` types may not have all their fields correctly discovered and serialized. Similarly, complex inheritance structures involving `__databind_settings__` on subclasses can introduce subtle bugs or unexpected behavior.","severity":"gotcha","affected_versions":"<4.5.3 (for Generic inheritance), <4.5.4 (for __databind_settings__ issues)"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Upgrade `databind-json` to version `4.5.4` or newer. If you have migrated, ensure your `databind` package is at `4.5.4` or newer.","cause":"This error can occur in older versions when `Union` settings are inherited via the Method Resolution Order (MRO) in complex dataclass hierarchies, leading to infinite recursion during de/serialization.","error":"RecursionError: maximum recursion depth exceeded while calling a Python object"},{"fix":"Upgrade `databind-json` to version `4.5.3` or newer. If you have migrated, ensure your `databind` package is at `4.5.3` or newer.","cause":"Versions prior to `4.5.3` had issues correctly processing `typing.Union` types that included `typing.Literal` as one of the possible types during de/serialization.","error":"TypeError: object of type Literal cannot be used as a type argument"},{"fix":"Upgrade `databind-json` to version `4.5.3` or newer. If you have migrated, ensure your `databind` package is at `4.5.3` or newer.","cause":"Dataclasses inheriting from uninstantiated `typing.Generic` classes in versions prior to `4.5.3` did not have all their fields properly discovered and serialized by the library.","error":"Dataclass fields missing from serialized output when inheriting from Generic"}]}