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

  • SEARCH
  • Home
  • 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 9179581
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:50:00+00:00 2026-06-17T17:50:00+00:00

i have a class (non model) from django.utils import simplejson class myclass: def __init(self):

  • 0

i have a class (non model)

from django.utils import simplejson
class myclass:
    def __init(self):
        self.x = "1877"
        self.y = "1410"
        self.z = "400"
        self.w = "67"
        self.a ="0"
        self.b = "1"
        self.c = "319996"
        self.d ="187702"
        self.t = "168000"

def ajaxRes(request):
    mobj = myclass;
    json_str = simplejson.dumps(mobj)
    return HttpResponse(json_str,mimetype ="application/x-javascript")

i got the follwoing error :

class myapp.views.myclass at 0x7faadc020c18> is not JSON serializable

I also tried the serializers of django but it seems only work for model class

from django.core import serializers
data = serializers.serialize("json", mobj.objects.all())

throws error that mobj does not have any attribute objects.

How can one serialize a class in django [json format].

  • 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-17T17:50:01+00:00Added an answer on June 17, 2026 at 5:50 pm

    You need to prepare simplejson serializer to handle your class:

    from django.utils import simplejson
    
    class HandleMyClass(simplejson.JSONEncoder):
         """ simplejson.JSONEncoder extension: handle MyClass"""
         def default(self, obj):
             if isinstance(obj, MyClass):
                 return obj.__dict__
             return simplejson.JSONEncoder.default(self, obj)
    
    data = simplejson.dumps( dictionary, cls=HandleMyClass )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Django model class with a non-model-field property, ex: def _get(self): return
So I can create Django model like this: from django.db import models class Something(models.Model):
I have the following: MODEL.PY LIST = (('Manager', 'Manager'),('Non-Manager', 'Non-Manager'),) class Employee(models.Model): fname =
I've got Django tables like the following (I've removed non-essential fields): class Person(models.Model): nameidx
I tried the following in Clojure, expecting to have the class of a non-lazy
I have non-template class with a templatized constructor. This code compiles for me. But
I have a class (called Employee. non static) defined in a class library. I
I have a non-Activity class (let's call it NonActivity) that needs to post a
I have a problem to test my non activity-class which need the context of
I have a static field in a non static class. public class DBtools {

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.