I need to serialize a tuple that contains a raw python datatype or in other words a built in class eg. int/str. But the json library throws an error like TypeError: Object of type type is not JSON serializable
Full traceback:
Traceback (most recent call last):
File "C:\Users\ns877v\git\analytics-kronos-worker\useful_snippets\2.py", line 2, in <module>
json.dumps(int)
File "C:\Users\ns877v\AppData\Local\Programs\Python\Python37\lib\json\__init__.py", line 231, in dumps
return _default_encoder.encode(obj)
File "C:\Users\ns877v\AppData\Local\Programs\Python\Python37\lib\json\encoder.py", line 199, in encode
chunks = self.iterencode(o, _one_shot=True)
File "C:\Users\ns877v\AppData\Local\Programs\Python\Python37\lib\json\encoder.py", line 257, in iterencode
return _iterencode(o, 0)
File "C:\Users\ns877v\AppData\Local\Programs\Python\Python37\lib\json\encoder.py", line 179, in default
raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type type is not JSON serializable
[Finished in 0.4s]
Run this to replicate:
import json
json.dumps(int)