Object-Oriented JSON (OOJ) is a universal libraryfor working with JSON in Python, providing simplicityand convenience in serializing and deserializingcomplex objects.
Project description
Object-Oriented JSON (OOJ)
is a universal library for working with JSON in Python, providing simplicity and convenience in serializing and deserializing complex objects.
Table of Contents
Installation
Install the library via pip
:
pip install ooj
Core Classes
JsonEntity
An abstract class representing the base for all JSON objects. It provides methods for converting objects to a dictionary and checking their equality.
Entry
A class representing a key-value pair in JSON. It implements methods for serialization to a dictionary and comparison.
BaseTree
A class representing a tree of JSON objects. It supports adding and removing elements and serializing to a dictionary.
RootTree
and Tree
Classes extending BaseTree
that provide structuring for nested objects.
TreeConverter
A class for converting JSON data into RootTree
and Tree
structures.
Usage Example
from ooj import TreeConverter
json_data = {
"name": "Alice",
"age": 30,
"address": {
"street": "123 Main St",
"city": "Anytown"
}
}
root_tree = TreeConverter.to_root_tree(json_data)
print(root_tree)
Support for Nested Types
The OOJ library supports deserializing complex nested types, allowing you to easily handle structures with arbitrary nesting. When serializing and deserializing, you can use annotations to specify data types, simplifying the work with custom objects and arrays.
Example:
from ooj import Serializer
class Address(JsonEntity):
def __init__(self, street: str, city: str):
self.street = street
self.city = city
def to_dict(self):
return {
"street": self.street,
"city": self.city
}
class Person(JsonEntity):
def __init__(self, name: str, age: int, address: Address):
self.name = name
self.age = age
self.address = address
def to_dict(self):
return {
"name": self.name,
"age": self.age,
"address": self.address.to_dict()
}
address = Address("123 Main St", "Anytown")
person = Person("Alice", 30, address)
json_dict = person.to_dict()
print(json_dict)
License
This project is licensed under the Apache 2.0 License. See the LICENSE
file for more information.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file ooj-0.1.1.tar.gz
.
File metadata
- Download URL: ooj-0.1.1.tar.gz
- Upload date:
- Size: 17.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b51328a8fbe91f725487a50e6b7ab153c3cd195b0c241d19e7b5d4b0e52d4fc3 |
|
MD5 | ba3050fc51d32a2e84eb63436de22ed8 |
|
BLAKE2b-256 | 69939f27d3f88aff237472f629f9ed53c497cc1b9aad11c9045724d4fdcf9df1 |