OOJ (Object Oriented JSON) is a Python library designed to simplify working with JSON data. It allows you to create, process, and interact with JSON data using an object-oriented approach.
Project description
The OOJ
library is a Python package that simplifies working with JSON files. It provides methods to read, write, add, remove, and replace elements in a JSON file.
Installation
You can install the OOJ
library directly from PyPI:
On Windows:
pip install ooj
On Linux/MacOS:
pip3 install ooj
Usage
Import library
import ooj
Working with JsonFile
Creating a JsonFile object
Create a JsonFile
object:
my_file = ooj.JsonFile('your/path/to/file.json')
Read and write
Read or write:
data = {
"name": "Jane",
"age": 22,
"is_happy": True
}
my_file.write(data)
print(my_file.read())
PS:
>>> {
>>> "name": "Jane",
>>> "age": 22,
>>> "is_happy": True
>>> }
Sampling
data = {
"1": -7,
"2": 3,
"3": 9
}
my_file.write(data)
selected_keys_dict = my_file.select(range(0, 10))
print(selected_keys_dict)
PS:
>>> {"2": 3, "3": 9}
Create serialization
You can serialize and deserialize objects.
Creating a serializer
from ooj import JsonSerializer
from ooj.excptions import NotSerializableError
# Options for serialization
options = {
"indent": 4,
"ignore_errors": NotSerializableError
}
serializer = JsonSerializer(options=options)
Serialize the object
class Person:
def __init__(self, name, age):
self.name = name
self.age = age
serialized_person = serializer.serialize(Person("Mike", 29))
print(serialized_person)
PS:
>>> {
>>> 'name': 'Mike',
>>> 'age': 29
>>> }
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
ooj-0.0.5.tar.gz
(13.9 kB
view details)
File details
Details for the file ooj-0.0.5.tar.gz
.
File metadata
- Download URL: ooj-0.0.5.tar.gz
- Upload date:
- Size: 13.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 60dfb6cf1feb8da71fedfb5b5220e9b98c0d9d69a8e6457e19661a8d1596ffeb |
|
MD5 | bebd7da31bfb7bdce5454e38bb661907 |
|
BLAKE2b-256 | 59e36d7c625bb9c18a9b5ed3675ad4d25841cf3116a587359245b81e0f5faa31 |