When I try to run the following code:
import jsond = {'testing': {1, 2, 3}}
json_string = json.dumps(d)
I get the following exception:
Traceback (most recent call last):File "json_test.py", line 4, in <module>json_string = json.dumps(d)File "/usr/lib/python2.7/json/__init__.py", line 243, in dumpsreturn _default_encoder.encode(obj)File "/usr/lib/python2.7/json/encoder.py", line 207, in encodechunks = self.iterencode(o, _one_shot=True)File "/usr/lib/python2.7/json/encoder.py", line 270, in iterencodereturn _iterencode(o, 0)File "/usr/lib/python2.7/json/encoder.py", line 184, in defaultraise TypeError(repr(o) + " is not JSON serializable")
TypeError: set([1, 2, 3]) is not JSON serializable
What can I do to successfully use json.dumps
with objects containing set
s?