Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
JSON Dump and JSON Load
#5
json.dump() and json.load() are just the tip of the iceberg. Using json requires a lot more than just that.

A JSON file can only contain numbers, strings, datetime, list and dictionary objects. You cannot dump a fxWarMapStatic object to a json file, and you cannot load a json file and have it return a fxWarMapStatic object. You'll have to write code that can convert your object to things json can serialize. Dumping the __dict__ can do this if the dictionary only contains the types mentioned above, but often you need to write some extra code to make a class "serializable".

Deserializing is a lot more work. When you load a json file you usually get a dictionary or a list. The only types in the object returned by json.load() are numbers, strings. datetime, lists and dictionaries. If you want these to be different classes, you need to write some code that takes the object returned from json.load() and create/restore the objects you want.
Reply


Messages In This Thread
JSON Dump and JSON Load - by foxholenoob - Oct-12-2023, 12:27 AM
RE: JSON Dump and JSON Load - by foxholenoob - Oct-12-2023, 12:46 AM
RE: JSON Dump and JSON Load - by deanhystad - Oct-12-2023, 01:59 AM
RE: JSON Dump and JSON Load - by foxholenoob - Oct-12-2023, 04:01 AM
RE: JSON Dump and JSON Load - by deanhystad - Oct-12-2023, 04:25 AM
RE: JSON Dump and JSON Load - by foxholenoob - Oct-12-2023, 05:39 AM
RE: JSON Dump and JSON Load - by deanhystad - Oct-12-2023, 06:03 AM
RE: JSON Dump and JSON Load - by buran - Oct-12-2023, 07:10 AM
RE: JSON Dump and JSON Load - by foxholenoob - Oct-12-2023, 07:21 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Convert Json to table format python_student 4 15,395 Dec-05-2024, 04:32 PM
Last Post: Larz60+
  Trying to get JSON object in python and process it further Creepy 2 1,129 Oct-24-2024, 08:46 AM
Last Post: buran
  Write json data to csv Olive 6 1,515 Oct-22-2024, 06:59 AM
Last Post: Olive
  get JSON string from URL with Windows credentials shwfgd 0 712 Aug-27-2024, 10:08 PM
Last Post: shwfgd
  JSON File - extract only the data in a nested array for CSV file shwfgd 2 1,204 Aug-26-2024, 10:14 PM
Last Post: shwfgd
  Python beginner needs json help rwskinner 1 701 Aug-22-2024, 05:30 PM
Last Post: deanhystad
  Trying to generating multiple json files using python script dzgn989 4 2,678 May-10-2024, 03:09 PM
Last Post: deanhystad
  encrypt data in json file help jacksfrustration 1 2,434 Mar-28-2024, 05:16 PM
Last Post: deanhystad
Exclamation Json API JayPy 4 1,803 Mar-04-2024, 04:28 PM
Last Post: deanhystad
  json loads throwing error mpsameer 8 5,057 Jan-23-2024, 07:04 AM
Last Post: deanhystad

Forum Jump:

User Panel Messages

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