Python Forum
Object of type 'Status' is not JSON serializable
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Object of type 'Status' is not JSON serializable
#1
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?
Reply
#2
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
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  declaring object parameters with type JonWayn 2 889 Dec-13-2022, 07:46 PM
Last Post: JonWayn
  Deserialize Complex Json to object using Marshmallow tlopezdh 2 2,114 Dec-09-2021, 06:44 PM
Last Post: tlopezdh
Star Type Error: 'in' object is not callable nman52 3 3,381 May-01-2021, 11:03 PM
Last Post: nman52
  finding and deleting json object GrahamL 1 4,836 Dec-10-2020, 04:11 PM
Last Post: bowlofred
  Serializable JarredAwesome 4 2,210 Nov-19-2020, 11:50 PM
Last Post: JarredAwesome
  TypeError: 'type' object is not subscriptable Stef 1 4,513 Aug-28-2020, 03:01 PM
Last Post: Gribouillis
  isinstance() always return true for object type check Yoki91 2 2,551 Jul-22-2020, 06:52 PM
Last Post: Yoki91
  AttributeError: type object 'FunctionNode' has no attribute '_TestValidateFuncLabel__ binhduonggttn 0 2,241 Feb-19-2020, 11:29 AM
Last Post: binhduonggttn
  Type hinting - return type based on parameter micseydel 2 2,468 Jan-14-2020, 01:20 AM
Last Post: micseydel
  Object of type set is not JSON serializable enigma619 5 12,218 Dec-19-2019, 03:30 PM
Last Post: enigma619

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020