--- id: json-fix version: "1.0.2" license: MIT license_treatment: permissive maintenance: aging --- # json-fix — allow custom class json behavior on builtin json object License: permissive · Maintenance: aging · Downloads: 136.1K/mo ## What it is and what it does json-fix is a lightweight patch to Python's built-in `json` module that enables custom serialization behavior for user-defined classes. When you import it, it modifies `json.dumps()` to recognize and call a `__json__()` method on any object, allowing you to define how your class should be converted to JSON-compatible types. This solves the problem of third-party code attempting to serialize your objects without knowing how to handle them—instead of forking their code or catching exceptions, you simply define the serialization logic in your class. The package provides two mechanisms for controlling serialization: an `override_table` for intercepting specific classes before they check for a `__json__` method, and a `fallback_table` for providing default serialization when neither a `__json__` method nor an override rule exists. Both tables use checker functions as keys, prioritizing the most recently added entry. The patch is described as safe, backwards-compatible, and reversible. Use it for: - Enable JSON serialization of custom classes without modifying their definition or the calling code that uses json.dumps(). - Intercept serialization of third-party library objects by adding override rules without forking the library. - Provide a fallback serialization strategy for all objects with a `__dict__` attribute, making arbitrary Python classes JSON-serializable by default. - Migrate codebases that rely on toJSON() patterns to Python while preserving the same serialization approach. ## Worth the install? AI-flagged interpretation of the facts above — verify before relying. Patches Python's built-in `json` module to recognize and call a `__json__` method on custom classes during serialization, similar to JavaScript's `toJSON`. Yes, if you need to customize JSON serialization for classes you control or intercept serialization of third-party objects. The package has low install friction, no dependencies, and a permissive MIT license. However, the aging maintenance status (295 days since last release) suggests limited active development—install it only if the `__json__` pattern solves a specific serialization problem you face. ## Install pip install json-fix uv add json-fix poetry add json-fix ## Installing json-fix Before you install: Low install friction with no runtime dependencies. Maintenance status is aging—last release was 295 days ago, though the repository remains active and not archived. License in practice: MIT license permits commercial and private use with minimal restrictions; you must include a copy of the license and copyright notice. Quickstart: pip install json-fix import json_fix import json class MyClass: def __json__(self): return self.__dict__ obj = MyClass() print(json.dumps(obj)) Requires Python 3.6 or later; json_fix must be imported before json.dumps is called on objects you want to serialize. Verify before relying: - Whether the override_table's last-entry-wins priority behavior is reliable across all Python versions. - Performance impact when using large override_table or fallback_table dictionaries with many checker functions. - Real-world adoption and whether the aging maintenance status indicates the package is stable or abandoned. ## Package facts - License: MIT (permissive) - Python support: supports_current - Install friction: low - Maintenance: aging - Downloads: 136.1K/month (top 15,000 on PyPI) - Known vulnerabilities: none known ## Tags custom json serialization, json dumps custom objects, define json behavior for classes, json __json__ method, serialize custom classes to json, json encoder for custom types, override json serialization, json-serialization, monkey-patching [View on SkillFed](https://skillfed.io/packages/json-fix) · [View on PyPI](https://pypi.org/project/json-fix/)