How to JSON serialize sets?
You can create a custom encoder that returns a list when it encounters a set. Here’s an example: >>> import json >>> class SetEncoder(json.JSONEncoder): … def default(self, obj): … if isinstance(obj, set): … return list(obj) … return json.JSONEncoder.default(self, obj) … >>> json.dumps(set([1,2,3,4,5]), cls=SetEncoder) ‘[1, 2, 3, 4, 5]’ You can detect other types this way … Read more