{"id":21485,"library":"json-fix","title":"json-fix","description":"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.","status":"active","version":"1.0.2","language":"python","source_language":"en","source_url":"https://github.com/jeff-hykin/json_fix","tags":["json","serialization","custom-class","patch"],"install":[{"cmd":"pip install json-fix","lang":"bash","label":"Install via pip"}],"dependencies":[],"imports":[{"note":"Simply importing the module patches json; no direct symbol needed.","wrong":"from json_fix import ...","symbol":"json_fix","correct":"import json_fix"}],"quickstart":{"code":"import json\nimport json_fix\n\nclass Person:\n    def __init__(self, name, age):\n        self.name = name\n        self.age = age\n    def __json__(self):\n        return {\"name\": self.name, \"age\": self.age}\n\nperson = Person(\"Alice\", 30)\nprint(json.dumps(person))  # {\"name\": \"Alice\", \"age\": 30}","lang":"python","description":"Imports json_fix to patch json module, then defines a class with __json__ method for custom serialization."},"warnings":[{"fix":"Ensure no other code depends on json raising TypeError for custom objects without __json__.","message":"json_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.","severity":"breaking","affected_versions":">=0.1.0"},{"fix":"Return a native Python object (e.g., dict) from __json__; do not call json.dumps inside it.","message":"The __json__ method must return a JSON-serializable object (dict, list, string, etc.), not a raw JSON string. Returning a string will double-encode it.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Use built-in json module for serialization when using json_fix.","message":"json_fix only works with the built-in json module. It does not affect third-party serializers like orjson, rapidjson, or ujson.","severity":"gotcha","affected_versions":">=0.1.0"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Add 'import json_fix' at the top of your script and define a __json__ method on your class that returns a serializable object.","cause":"The import 'import json_fix' is missing or the class does not have a __json__ method.","error":"TypeError: Object of type MyClass is not JSON serializable"},{"fix":"Run 'pip install json-fix' to install the package.","cause":"The package is not installed.","error":"json_fix not found"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}