JSON Objects

13 views
Skip to first unread message

yingi keme

unread,
Sep 16, 2017, 10:25:58 AM9/16/17
to Django users
Say you have a simple class

class Cart(object):
def _init_(self, name, age):
self.name = name
self.age = age

And then you have an instance of the class

T = Cart('john', 23)

How will you serialize the object instance T using json?

I know json serializes limited data structure. But i think there is a custom way to serialize and deserialize Object instances.

Please help.

Jani Tiainen

unread,
Sep 16, 2017, 10:31:48 AM9/16/17
to django...@googlegroups.com
Hi

One of the simplest ways is to use special serializer. At least django-nap and django-rest-framework do have excellent serializers you can leverage.

Django itself also has serializer you can use. https://docs.djangoproject.com/en/1.11/topics/serialization/

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/67356dad-a1cd-40f0-aaf5-8a32ed481676%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

yingi keme

unread,
Sep 16, 2017, 11:06:40 AM9/16/17
to django...@googlegroups.com
I will check it out, i have just used the third party package jsonpickle. And it was easy to use

Thanks a lot

Yingi Kem
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
Reply all
Reply to author
Forward
0 new messages