-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Daniel Osypenko <[email protected]>
- Loading branch information
1 parent
cf87a64
commit 0338af9
Showing
7 changed files
with
51 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import json | ||
|
||
|
||
class SetToListJSONEncoder(json.JSONEncoder): | ||
""" | ||
The CustomJSONEncoder class is a subclass of json.JSONEncoder designed to handle the serialization of Python | ||
objects into JSON format, with a specific focus on converting set objects into lists. | ||
This is necessary because the default JSON encoder in Python does not support set objects, which are not a valid | ||
JSON data type. | ||
This way we avoid "TypeError: Object of type set is not JSON serializable" | ||
Usage: | ||
json.dumps(data, cls=SetToListJSONEncoder) | ||
""" | ||
|
||
def default(self, obj): | ||
if isinstance(obj, set): | ||
return list(obj) | ||
return super().default(obj) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters