Skip to main content

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

PyPI PyPI - Downloads Downloads last 6 month PyPI - License


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
}

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.3.6.tar.gz (10.0 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page