>>> j = '{"action": "print", "method": "onData", "data": "Madan Mohan"}'
>>> import json
>>> 
>>> class Payload(object):
...     def __init__(self, j):
...         self.__dict__ = json.loads(j)
... 
>>> p = Payload(j)
>>>
>>> p.action
'print'
>>> p.method
'onData'
>>> p.data
'Madan Mohan'
Answer from John La Rooy on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › python › deserialize-json-to-object-in-python
Deserialize JSON to Object in Python - GeeksforGeeks
July 15, 2025 - load() : to deserialize a JSON formatted stream ( which supports reading from a file) to a Python object.
Discussions

De/Serializing JSON In Python, While Keeping Your Types
Why didn't pydantic work for you, and why not follow PEP8 with regards to tabs and spaces? More on reddit.com
🌐 r/Python
12
19
October 10, 2022
For fun, I created a library to serialize / deserialize any python object into JSON
How it's different than jsonpickle ? More on reddit.com
🌐 r/Python
9
11
August 27, 2022
serialization and deserialization question
Is there a reason you're not just using a database (like SQLite in a case like this)? If you're determined to use text files, why not simply json which already has tools to work with it? More on reddit.com
🌐 r/learnpython
10
1
August 14, 2023
Serialize/deserialize (JSON) class attributes recursively across hierarchy of classes.
Seems like the wrong solution. Pickle can marshal object instances. Alternatively, have you considered xmlrpc for your communication? More on reddit.com
🌐 r/learnpython
15
1
September 28, 2014
🌐
Python
docs.python.org › 3 › library › json.html
JSON encoder and decoder — Python 3.14.3 documentation
February 23, 2026 - Other than the ensure_ascii parameter, this module is defined strictly in terms of conversion between Python objects and Unicode strings, and thus does not otherwise directly address the issue of character encodings. The RFC prohibits adding a byte order mark (BOM) to the start of a JSON text, and this module’s serializer does not add a BOM to its output. The RFC permits, but does not require, JSON deserializers to ignore an initial BOM in their input.
🌐
GitHub
github.com › tbebekis › Python-Json
GitHub - tbebekis/Python-Json: A solution on how to serialize/deserialize objects (and complex objects) in Python · GitHub
Python supports Json by providing a set of functions and classes, found in the json package. The dumps() function serializes an object to a Json formatted string. The loads() function deserializes a Json string into a Python dictionary.
Author   tbebekis
🌐
Reddit
reddit.com › r/python › de/serializing json in python, while keeping your types
r/Python on Reddit: De/Serializing JSON In Python, While Keeping Your Types
October 10, 2022 -

Short writeup of the motivations I had for writing a Python serialization library
https://medium.com/@steffen.cucos/de-serializing-json-in-python-4053366bc8ad
Coming from the world of Java I was used to dealing with external systems like DBs & APIs that communicate over varying messaging formats, but the details of how an object was sent or received over the wire was always hidden behind libraries that handled the process of turning a Java object into JSON & JSON back into a real Java object.

In Python it seems like the general approach to this serialization issue is to manually handle turning objects into JSON (hand written to_json, JSON.dumps(obj.__dict__ ), etc.), and to manually reconstruct an instance of an object for deserialization.

In a personal project of mine I ran into this issue on 2 fronts. Sending/Receiving data over an API, and saving/reading data from mongodb.

In order to solve the issue, I wrote a library called pserialization to automate the task of turning objects into JSON, and turning JSON back into an object.

The serialization part is actually fairly simple. Much like the JSON.dumps(obj.__dict__) approach, the library recursively serializes each field in an objects __dict__ attribute, and uses the type of each field to inform what JSON primitive to serialize into (int, float, bool, array, {}).

The deserialization part is more complicated, and requires you to tell the library what object you want to turn some JSON into, and to have type hints (either as a dataclass or in the __init__ of the object). Using the type information the library can know which types need to be instantiated and with which fields.

TLDR:
Upset that there is no generic way to convert from python objects to JSON and back, so wrote a library that uses type hints to automate the de/serialization process.

Source code:
https://github.com/SteffenCucos/PSerialization

🌐
GeeksforGeeks
geeksforgeeks.org › python › serialize-and-deserialize-complex-json-in-python
Serialize and Deserialize complex JSON in Python - GeeksforGeeks
August 11, 2025 - When data stored in a Python object only contains basic types (strings, numbers, booleans, etc.), it can be easily serialized and deserialized using Python’s built-in json module and object’s __dict__ attribute.
Find elsewhere
🌐
AskPython
askpython.com › home › serialize and deserialize json to objects in python
Serialize and Deserialize JSON to objects in Python - AskPython
July 5, 2021 - Post which, we pass the object referring the JSON file to the load() function and deserialize it into dictionary form. import json data = open('info.json',) op = json.load(data) print(op) print("Datatype after de-serialization : " + str(type(op))) ...
🌐
Real Python
realpython.com › lessons › deserializing-json-data
Deserializing JSON Data (Video) – Real Python
The json module exposes two methods for deserializing JSON · load() will load JSON data from a file-like object. We use this method when we’re reading in data from a file-like object. loads() will load JSON data from a string containing JSON-encoded data. Unless your encoded data is something very simple, these methods will most likely return a Python dict or list containing your deserialized data.
Published   March 28, 2019
🌐
MojoAuth
mojoauth.com › serialize-and-deserialize › serialize-and-deserialize-json-with-python
Serialize and Deserialize JSON with Python | Serialize & Deserialize Data Across Languages
By the end, you'll be able to ... numbers, and booleans can be directly converted into JSON strings using the json.dumps() function....
🌐
HowToDoInJava
howtodoinjava.com › home › python json › python json – custom class deserialization
Python JSON - Custom Class Deserialization Example
October 1, 2022 - Learn to deserialize JSON string and convert deserialized Python dictionary object to a custom class by extending JSONDecoder or object_hook method.
🌐
Sololearn
sololearn.com › en › Discuss › 3306194 › deserialize-json-object-in-python
Deserialize JSON object in python | Sololearn: Learn to code for FREE!
October 25, 2024 - What it sounds like is that you are encountering a common challenge when working with JSON data and dataclasses in Python: ensuring flexibility while maintaining type safety and structure. -> The issue arises when the JSON structure is dynamic or when you only need to access a subset of its fields.
🌐
Medium
medium.com › @idelossantosruiz › mastering-json-in-python-oop-a-practical-guide-65b39e868c33
Mastering JSON in Python OOP: A Practical Guide | by Ildeberto de los Santos Ruiz | Medium
June 4, 2025 - In this tutorial, we’ll explore how to work with JSON data within an object-oriented Python project. We’ll cover how to serialize (convert objects to JSON) and deserialize (convert JSON back into objects) using Python’s built-in json module.
🌐
PyPI
pypi.org › project › deserialize
deserialize · PyPI
To get started, just run pip install deserialize ... class MyThing: def __init__(self, a, b): self.a = a self.b = b @staticmethod def from_json(json_data): a_value = json_data.get("a") b_value = json_data.get("b") if a_value is None: raise ...
      » pip install deserialize
    
Published   Nov 11, 2025
Version   2.3.0
🌐
Finxter
blog.finxter.com › home › learn python blog › 5 best ways to deserialize complex json to object in python
5 Best Ways to Deserialize Complex JSON to Object in Python - Be on the Right Side of Change
February 23, 2024 - This example illustrates how to create a UserSchema that defines the structure of the JSON input. The loads() method of the schema is then used to deserialize the JSON data into a Python dictionary that adheres to the schema’s structure, including type validation.
🌐
Medium
yuchen52.medium.com › serialize-and-deserialize-complex-json-in-python-205ecc636caa
Serialize and Deserialize complex JSON in Python | by Yuchen Z. | Medium
September 8, 2021 - import jsonclass Student(object): def __init__(self, first_name: str, last_name: str): self.first_name = first_name self.last_name = last_name student = Student(first_name="Jake", last_name="Doyle") json_data = json.dumps(student)
🌐
Envato Tuts+
code.tutsplus.com › home › python
Serialization and Deserialization of Python Objects: Part 1 | Envato Tuts+
May 26, 2022 - The json module doesn't know anything about the A class or even the standard datetime object. It just deserializes everything by default to the Python object that matches its type system.
🌐
Tutorialspoint
tutorialspoint.com › python › python_json.htm
Python - JSON
The json module in Python provides methods for working with JSON (JavaScript Object Notation). It allows you to serialize and deserialize Python objects to and from JSON format, which is a commonly used data interchange format.
🌐
GitHub
github.com › toricode › pythondeserializejsonfile
GitHub - toricode/PythonDeserializeJSONFile: Python Deserialize JSON File to Object · GitHub
Python Deserialize JSON File to Object. Contribute to toricode/PythonDeserializeJSONFile development by creating an account on GitHub.
Author   toricode