I spent hours trying to figure out how to subclass and modify json.JSONEncoder to override how it encodes enum.Enum instances before learning that it literally wasn't possible, and that the only solution is to traverse my data structure and convert the enums myself in a pre-processing step.
Then I tried finding an existing solution to the problem of traversing arbitrary Python data structures, which I assumed was a very common and well-solved problem (either in Standard Library or PyPI), but I can't seem to find any.
You didn't provide an example of what you're trying to achieve, but from the description, it appears you were after something like this:
Output:
If this doesn't solve your problem, you should provide a more specific example of what you're trying to achieve, what you tried and where you got stuck.
Edit: your comment suggested that the
default()doesn't get called for enums - but that's not correct. For example, if you change the class like this:The output becomes: