Python Forum

Full Version: Object of type 'Status' is not JSON serializable
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
with open('json_filtered.txt', 'w') as file:
        file.write(json.dumps(json_list,indent=4))
give the following errors


Error:
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-27-af41dfc85e11> in <module>() 2 3 with open('json_filtered.txt', 'w') as file: ----> 4 file.write(json.dumps(json_list,indent=4)) C:\ProgramData\Anaconda3\lib\json\__init__.py in dumps(obj, skipkeys, ensure_ascii, check_circular, allow_nan, cls, indent, separators, default, sort_keys, **kw) 236 check_circular=check_circular, allow_nan=allow_nan, indent=indent, 237 separators=separators, default=default, sort_keys=sort_keys, --> 238 **kw).encode(obj) 239 240 C:\ProgramData\Anaconda3\lib\json\encoder.py in encode(self, o) 199 chunks = self.iterencode(o, _one_shot=True) 200 if not isinstance(chunks, (list, tuple)): --> 201 chunks = list(chunks) 202 return ''.join(chunks) 203 C:\ProgramData\Anaconda3\lib\json\encoder.py in _iterencode(o, _current_indent_level) 426 yield _floatstr(o) 427 elif isinstance(o, (list, tuple)): --> 428 yield from _iterencode_list(o, _current_indent_level) 429 elif isinstance(o, dict): 430 yield from _iterencode_dict(o, _current_indent_level) C:\ProgramData\Anaconda3\lib\json\encoder.py in _iterencode_list(lst, _current_indent_level) 323 else: 324 chunks = _iterencode(value, _current_indent_level) --> 325 yield from chunks 326 if newline_indent is not None: 327 _current_indent_level -= 1 C:\ProgramData\Anaconda3\lib\json\encoder.py in _iterencode(o, _current_indent_level) 435 raise ValueError("Circular reference detected") 436 markers[markerid] = o --> 437 o = _default(o) 438 yield from _iterencode(o, _current_indent_level) 439 if markers is not None: C:\ProgramData\Anaconda3\lib\json\encoder.py in default(self, o) 178 """ 179 raise TypeError("Object of type '%s' is not JSON serializable" % --> 180 o.__class__.__name__) 181 182 def encode(self, o): TypeError: Object of type 'Status' is not JSON serializable

Please, can someone help me?
We cannot be of much help without seeing your Status class. Based on the error you will need to implement some form of custom serialization for this