Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8122793
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T05:56:56+00:00 2026-06-06T05:56:56+00:00

Does python support random json serialization? I get this error: Traceback (most recent call

  • 0

Does python support random json serialization? I get this error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "commands.py", line 36, in toJson
    return json.dumps(self)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/__init__.py", line 231, in dumps
    return _default_encoder.encode(obj)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/encoder.py", line 201, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/encoder.py", line 264, in iterencode
    return _iterencode(o, 0)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/encoder.py", line 178, in default
    raise TypeError(repr(o) + " is not JSON serializable")
TypeError: <commands.SampleCommand object at 0x105d957d0> is not JSON serializable

Snippet:

class SampleCommand(Command):
    def __init__(self,message=None):
        super(Command, self).__init__()
        pass

    def parse(self):
        pass

    def toJson(self):
        return json.dumps(self)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T05:56:58+00:00Added an answer on June 6, 2026 at 5:56 am

    json within python by default can only handle certain objects like dictionaries, list and basic types such as ints, strings and so on for more complex types you need to define your own serialization scheme

    >>> help(json)
    Extending JSONEncoder::
    
        >>> import json
        >>> class ComplexEncoder(json.JSONEncoder):
        ...     def default(self, obj):
        ...         if isinstance(obj, complex):
        ...             return [obj.real, obj.imag]
        ...         return json.JSONEncoder.default(self, obj)
        ...
        >>> dumps(2 + 1j, cls=ComplexEncoder)
        '[2.0, 1.0]'
        >>> ComplexEncoder().encode(2 + 1j)
        '[2.0, 1.0]'
        >>> list(ComplexEncoder().iterencode(2 + 1j))
        ['[', '2.0', ', ', '1.0', ']']
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can someone confirm that Python 2.6 ftplib does NOT support Unicode file names? Or
I know that Python doesn't support tail-call optimization. Does that mean a recursive procedure
Does PyTables support storing Python objects? something like this : dtype = np.dtype([('Name', '|S2'),
Does Python support short-circuiting in boolean expressions?
I read that Python does not actually support 2D arrays but rather an array
Does urllib2 in Python 2.6.1 support proxy via https? I've found the following at
Python-memcached is the official supported memcached driver for Django. Does it support Consistent hashing
(I'm sure this is a FAQ, but also hard to google) Why does Python
Python does not print traceback messages from exceptions raised in daemon threads. For example,
Python does not provide built-in support for multi-dimensional arrays. I need to develop an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.