🚀 Seamless JSON handling in Python 🐍
Project description
JsonIO
🚀 Seamless JSON Handling in Python 🐍
Overview • Features • Installation • Documentation • Usage • Contributions • License
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file ayrun_jsonio-0.1.0.tar.gz
.
File metadata
- Download URL: ayrun_jsonio-0.1.0.tar.gz
- Upload date:
- Size: 4.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.12.5 Windows/11
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 599f86eb61ecf55cac1950a563108c46aa6f7476d8d5f0fad8e5c0cb1b18182d |
|
MD5 | 003bea8603eb20d496afda8d676af18a |
|
BLAKE2b-256 | 53c1635b3c1705a52dff24b12fe3f70e9864db41954e0440d07a27367740d20f |
File details
Details for the file ayrun_jsonio-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: ayrun_jsonio-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.12.5 Windows/11
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b0d3c4f0dace1db9214f598910992c9eb144db7f4032aba739223c16018ee908 |
|
MD5 | 4a891ab73d40408a2230d6402bcc21a3 |
|
BLAKE2b-256 | 88efd4e6e698a50898df6eea6f4a608124171d8a10f9808407c86636afa48710 |