Skip to content

Instantly share code, notes, and snippets.

@loretoparisi
Last active April 3, 2019 14:05
Show Gist options
  • Save loretoparisi/8974f9fcd21d525cb150275a2dc70050 to your computer and use it in GitHub Desktop.
Save loretoparisi/8974f9fcd21d525cb150275a2dc70050 to your computer and use it in GitHub Desktop.
Simple JSON Set Encoder in Python
import json
class SetEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, set):
return list(obj)
return json.JSONEncoder.default(self, obj)
@loretoparisi
Copy link
Author

USAGE:

json.dumps(set(range(1000)), cls=SetEncoder)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment