json-fix
allow custom class json behavior on builtin json object
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-fixuv
uv add json-fixpoetry
poetry add json-fixInstalling 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
More Software Development packages
Provides backported and experimental type hints…
permissive · top 100 on PyPI
numpyNumPy provides an N-dimensional array object…
permissive · top 100 on PyPI
fastapiFastAPI is a Python web framework for building…
permissive · top 100 on PyPI
annotated-docProvides a way to document function parameters,…
permissive · top 100 on PyPI
typerTyper builds command-line applications from…
permissive · top 1,000 on PyPI
distlibDistlib provides low-level packaging utilities…
permissive · top 1,000 on PyPI
jsonableProvides an abstract base class for defining…
permissive · top 15,000 on PyPI
jsonconversionConverts arbitrary Python objects to JSON…
permissive · top 5,000 on PyPI
json-encoderProvides JSON serialization with…
unclear · top 15,000 on PyPI
orjsonorjson is a fast JSON serialization and…
copyleft · top 1,000 on PyPI
simplejsonsimplejson encodes Python objects to JSON and…
permissive · top 1,000 on PyPI
jsonsConverts Python objects (dataclasses, attrs…
permissive · top 5,000 on PyPI
json-numpyProvides lossless JSON encoding and decoding…
permissive · top 15,000 on PyPI
phpserializeConverts Python objects to and from PHP…
permissive · top 15,000 on PyPI
munchMunch provides a dictionary subclass that…
permissive · top 5,000 on PyPI
pyion2jsonConverts Amazon Ion documents and QLDB query…
permissive · top 15,000 on PyPI