Skip to main content

🚀 Seamless JSON handling in Python 🐍

Project description


EasyJSON
JsonIO

🚀 Seamless JSON Handling in Python 🐍

Created At Last Commit MIT License

OverviewFeaturesInstallationDocumentationUsageContributionsLicense

Overview

JsonIO is a high-level API for handling JSON serialization and deserialization in Python using the orjson library. It provides a simple and efficient way to work with JSON data, including support for custom types.

Features

  • Fast Serialization: Built on orjson, offering high-performance JSON serialization.

  • Custom Serialization: Easily extendable to handle non-standard data types with a custom encoder.

  • Convenient File Operations: Load and save JSON data directly from/to files.

Installation

You can install the module via pip:

pip install ayrun-jsonio

Documentation

The documentation website is still under development.

Usage

Basic Functions

The module provides the following main functions:

  • loads(data: Union[str, bytes]) -> Any: Deserialize a JSON string or bytes into a Python object.

  • load(filepath: Union[str, Path]) -> Any: Read a JSON file and return the corresponding Python object.

  • dumps(obj: Any, *, option: Optional[int] = None, default: Optional[Callable[[Any], Any]] = None) -> str: Serialize a Python object into a JSON string.

  • dump(obj: Any, filepath: Union[str, Path], *, option: Optional[int] = None, default: Optional[Callable[[Any], Any]] = None) -> None: Serialize a Python object and write it to a JSON file.

Example Usage

import uuid
from datetime import datetime
from decimal import Decimal

import jsonio

# Sample data
data = {
    "name": "Alice",
    "age": 30,
    "balance": Decimal("1234.56"),  # Decimal support
    "tags": {"json", "python"},       # Set support
    "uuid": uuid.uuid4(),             # UUID support
    "timestamp": datetime.now()        # Datetime support
}

# Serialize to JSON string
json_str = jsonio.dumps(data, default=my_custom_encoder)
print(json_str)

# Deserialize from JSON string
loaded_data = jsonio.loads(json_str)
print(loaded_data)

# Save to a file
jsonio.dump(data, "data.json", default=my_custom_encoder)

# Load from a file
file_data = jsonio.load("data.json")
print(file_data)

Contributions

Contributions are welcome! Please feel free to submit a pull request or open an issue if you encounter any problems or have suggestions for improvements.

License

This project is licensed under the MIT License. See the LICENSE file for details.

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

ayrun_jsonio-0.1.0.tar.gz (4.1 kB view hashes)

Uploaded Source

Built Distribution

ayrun_jsonio-0.1.0-py3-none-any.whl (4.6 kB view hashes)

Uploaded Python 3

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