
Research
2025 Report: Destructive Malware in Open Source Packages
Destructive malware is rising across open source registries, using delays and kill switches to wipe code, break builds, and disrupt CI/CD.
json-fix
Advanced tools
A pip module that lets you define a __json__ method, that works like toJSON from JavaScript.
(e.g. it magically gets called whenever someone does json.dumps(your_object))
From a technical perspective, this module is a safe, backwards-compatible, reversable patch to the built-in python json object that allows classes to specify how they should be serialized.
Because sometimes someone eles's code (e.g. a pip module) tries to serialize your object, like
import json
json.dumps(list_containing_your_object)
And you'd have to fork their code to make it not throw an error.
pip install json-fix
import json_fix # import this any time (any where) before the JSON.dumps gets called
# same file, or different file
class YOUR_CLASS:
def __json__(self):
# YOUR CUSTOM CODE HERE
# you probably just want to do:
# return self.__dict__
return "a built-in object that is natually json-able"
There's 2 ways; the aggressive override_table or the more collaboration-friendly fallback_table. Note: some really powerful stuff can be done safely with the fallback table!
CAUTION!
.__json__() method, the json.override_table will take priority.The override table is a dictionary. It has "check functions" as keys, and jsonifiers as values.
import json_fix # import this before the JSON.dumps gets called
import json
import pandas as pd
SomeClassYouDidntDefine = pd.DataFrame
# create a boolean function for identifying the class
check_func = lambda obj: isinstance(obj, SomeClassYouDidntDefine)
# then assign it to a function that does the converting
json.override_table[check_func] = lambda obj_of_that_class: json.loads(obj_of_that_class.to_json())
json.dumps([ 1, 2, SomeClassYouDidntDefine() ], indent=2) # dumps as expected
If you want all python classes to be jsonable by default, we can easily do that with the fallback table. The logic is if nothing in override table, and no .__json__ method, then check the fallback table.
import json_fix # import this before the JSON.dumps gets called
import json
# a checker for custom objects
checker = lambda obj: hasattr(obj, "__dict__")
# use the __dict__ when they don't specify a __json__ method
json.fallback_table[checker] = lambda obj_with_dict: obj_with_dict.__dict__
class SomeClass:
def __init__(self):
self.thing = 10
json.dumps([ 1, 2, SomeClass() ], indent=2) # dumps as expected
Like the override table, the most recently-added checker will have the highest priority.
FAQs
allow custom class json behavior on builtin json object
We found that json-fix demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Research
Destructive malware is rising across open source registries, using delays and kill switches to wipe code, break builds, and disrupt CI/CD.

Security News
Socket CTO Ahmad Nassri shares practical AI coding techniques, tools, and team workflows, plus what still feels noisy and why shipping remains human-led.

Research
/Security News
A five-month operation turned 27 npm packages into durable hosting for browser-run lures that mimic document-sharing portals and Microsoft sign-in, targeting 25 organizations across manufacturing, industrial automation, plastics, and healthcare for credential theft.