Python Forum
How to serialize custom class objects in JSON?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to serialize custom class objects in JSON?
#1
The Python documentation on JSON reads, "This simple serialization technique can handle lists and dictionaries, but serializing arbitrary class instances in JSON requires a bit of extra effort. The reference for the json module contains an explanation of this." But I can't seem to find the explanation in the JSON reference. I'm very new to programming, so it's probably there; it just went right over my head.

The reason I need to serialize the objects of a class I created is that I'm making a random NPC generator for tabletop RPGs, and each generated NPC is an instance of my NPC class with semi-randomized characteristics. Users will want to save the ones they like.

So how does one serialize a custom class object with JSON?

Thanks in advance.
Reply


Messages In This Thread
How to serialize custom class objects in JSON? - by Exsul1 - Sep-19-2019, 07:46 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How can I access objects or widgets from one class in another class? Konstantin23 3 993 Aug-05-2023, 08:13 PM
Last Post: Konstantin23
Question How to move a class to a custom module? python300 4 1,550 Mar-08-2022, 09:19 PM
Last Post: python300
  Custom file class deanhystad 11 4,358 Feb-01-2021, 05:09 PM
Last Post: nilamo
  Class objects Python_User 12 4,402 Aug-27-2020, 08:02 PM
Last Post: Python_User
  How to create and define in one line a 2D list of class objects in Python T2ioTD 1 2,023 Aug-14-2020, 12:37 PM
Last Post: Yoriz
  printing class properties from numpy.ndarrays of objects pjfarley3 2 1,939 Jun-08-2020, 05:30 AM
Last Post: pjfarley3
  Parse JSON multiple objects larkin_L 8 5,684 May-27-2020, 11:18 AM
Last Post: nuffink
  Help with lists and class objects AlluminumFoil 15 5,410 Jan-15-2020, 07:32 PM
Last Post: AlluminumFoil
  How do I write class objects to a file in binary mode? Exsul1 7 5,725 Sep-14-2019, 09:33 PM
Last Post: snippsat
  Do objects get their own copy of the class methods? Charles1 1 2,083 Feb-02-2019, 04:40 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

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