Solved Python – Object of type ABC is not JSON serializable

Problem: For your custom Python class if you try to use json serializer or try to return the object through REST api you see this error – Object of type ABC is not JSON serializable

Solution: For simple custom class you can use following solution

import json
class ABC:
  def to_json(self):
  return json.dumps(self, default=lambda o: o.__dict__, sort_keys=True, indent=4)

abc = ABC()
abc.to_json()

Leave a comment

Your comment

*