skillfed

json-fix

allow custom class json behavior on builtin json object

json-fix v1.0.2 136.1K downloads/30d#11,405 on PyPI26
Permissive license MIT AGING released

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 on this page — 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

json-fix on PyPI

pip

pip install json-fix

uv

uv add json-fix

poetry

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 the current Python release (>=3.6)
Install friction low — pure-Python wheel
Runtime dependencies none
Maintenance aging — 295 days since the last release
Last repo commit
First released
Downloads 136,129/month — #11,405 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: json_fix-1.0.2-py3-none-any.whl

Tags

custom json serializationjson dumps custom objectsdefine json behavior for classesjson __json__ methodserialize custom classes to jsonjson encoder for custom typesoverride json serialization
json-serializationmonkey-patching

More Software Development packages