want to convert object to json data.

1,615 views
Skip to first unread message

chiranjeevi.muttoju

unread,
Feb 9, 2010, 1:44:39 AM2/9/10
to Django users
Hi all,
I want to convert a given regular object to json object. i.e. I want
to create a function which takes the class object as parameter and it
should return the json object.
If anybody know please help me how to approach to get this.

Thanks and regards,
--chiranjeevi

Wayne Koorts

unread,
Feb 9, 2010, 1:47:25 AM2/9/10
to django...@googlegroups.com
> I want to convert a given regular object to json object. i.e. I want
> to create a function which takes the class object as parameter and it
> should return the json object.

Have a look at the built-in Django "serializers" module:

http://docs.djangoproject.com/en/dev/topics/serialization/#topics-serialization

Regards,
Wayne

chiranjeevi muttoju

unread,
Feb 9, 2010, 4:40:47 AM2/9/10
to django...@googlegroups.com
hi waine,
Thanks for ur reply. i got that. is there is any way to parse regular class objects(not model objects) to json data.. if u know please reply.


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.




--
Thanks and regards,
chiranjeevi.muttoju

bruno desthuilliers

unread,
Feb 9, 2010, 5:42:21 AM2/9/10
to Django users
On Feb 9, 10:40 am, chiranjeevi muttoju <chiru.bt...@gmail.com> wrote:
> hi waine,
> Thanks for ur reply. i got that. is there is any way to parse regular class
> objects(not model objects) to json data..

As documented, Django's json serialization is done using a bundled
version of simplejson, which is documented here:
http://simplejson.googlecode.com/svn/tags/simplejson-2.0.9/docs/index.html

As a side note, in Python, classes are actually objects too, so "class
object" usually refers to an object of type 'class'. What you're
referring to as 'class objects' are usually known as 'class
instances', or just 'objects' (since 1/ everything is an object, and
2/ all objects are instances of their class).

Also - and while the distinction indeed made sense in the current
context -, "model objects" (instances of Model's subclasses) ARE
actually "regular" python objects !-)

Reply all
Reply to author
Forward
0 new messages