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.0.tar.gz
.
File metadata
- Download URL: ooj-0.1.0.tar.gz
- Upload date:
- Size: 17.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | daca69ef3461ab6cd8606db8d9d645f3bee4e88bc59a4f43a0011f56e05251fb |
|
MD5 | 915de9200a5b1d1951654a726891631c |
|
BLAKE2b-256 | f4a30548de671ced9d2eeb2f7b3587de2852981ac2e8804f2d3d8f50701c9871 |