Registry / serialization / json-fix

json-fix

JSON →
library1.0.2pypypi✓ verified 85d ago

A library that allows custom JSON serialization for any class by adding a __json__ method, seamlessly patching the built-in json module. Current version 1.0.2, updated periodically.

pip install json-fix
INSTALL
IMPORT
SIG · JSON-FIX
J
json-fix
serializationpythonv1.0.2
Install
1.5s avg
Import
10ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.0.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.006s · 17.8MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.5s · import 0.004s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

json_fix
import json_fix
from json_fix import ...
Simply importing the module patches json; no direct symbol needed.

Imports json_fix to patch json module, then defines a class with __json__ method for custom serialization.

import json import json_fix class Person: def __init__(self, name, age): self.name = name self.age = age def __json__(self): return {"name": self.name, "age": self.age} person = Person("Alice", 30) print(json.dumps(person)) # {"name": "Alice", "age": 30}
Debug
Known issues
breakingjson_fix patches the built-in json module globally. If other code relies on the original behavior (e.g., raising TypeError on non-serializable objects), it may break.
fix
Ensure no other code depends on json raising TypeError for custom objects without __json__.
affects: >=0.1.0
gotchaThe __json__ method must return a JSON-serializable object (dict, list, string, etc.), not a raw JSON string. Returning a string will double-encode it.
fix
Return a native Python object (e.g., dict) from __json__; do not call json.dumps inside it.
affects: >=0.1.0
gotchajson_fix only works with the built-in json module. It does not affect third-party serializers like orjson, rapidjson, or ujson.
fix
Use built-in json module for serialization when using json_fix.
affects: >=0.1.0
Errors
Common errors & fixes
TypeError: Object of type MyClass is not JSON serializable
The import 'import json_fix' is missing or the class does not have a __json__ method.
fix
Add 'import json_fix' at the top of your script and define a __json__ method on your class that returns a serializable object.
json_fix not found
The package is not installed.
fix
Run 'pip install json-fix' to install the package.
Upgrade
Version history
1.0.2latest on PyPI · released Oct 23, 2025
Audit
Dependencies

No dependency data recorded yet.

Agent activity
6 hits · last 30 days
node
6
Resources
json-fix — pip install json-fix · libregistry