jsoncodable
Description
Easily create object from any dict/jsonstr/jsonfile and dict/jsonstr/jsonfile from any object
From v0.1.0 it is based on jsonpickle
Install
pip install jsoncodable
# or
pip3 install jsoncodable
Usage
from jsoncodable import JSONCodable, CompressionAlgorithm
class BirthDay(JSONCodable):
def __init__(
self,
month: int,
day: int
):
self.month = month
self.day = day
class Person(JSONCodable):
def __init__(
self,
name: str,
birth_month: int,
birth_day: int
):
self.name = name
self.birth_day = BirthDay(birth_month, birth_day)
person = Person(
name='John',
birth_month=7,
birth_day=7
)
person.jsonprint()
# prints
#
# {
# "name": "John",
# "birth_day": {
# "month": 7,
# "day": 7
# }
# }
Person.load(person.json).jsonprint()
# prints
#
# {
# "name": "John",
# "birth_day": {
# "month": 7,
# "day": 7
# }
# }
import os
# Save with compression
json_file_path = 'test.json'
for c in CompressionAlgorithm:
compressed_file_path = person.save(json_file_path, compression=c)
# returns a file path which has the compressed extension if not present at the end of your provided path
# also prints a message to let you know, that the path had been modified
Person.load(compressed_file_path).jsonprint()
# prints
#
# {
# "name": "John",
# "birth_day": {
# "month": 7,
# "day": 7
# }
# }
# Cleaning up
os.remove(compressed_file_path)
Dependencies
Metadata
Release files for jsoncodable 0.1.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| jsoncodable-0.1.7.tar.gz | 5.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| jsoncodable-0.1.7-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 11.5 kB
Release files / jsoncodable-0.1.7.tar.gz
| Download URL | jsoncodable-0.1.7.tar.gz |
|---|---|
| Size | 5.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1c4a51987545694a61c14d08dd4ff9abbcf80b9f1d675ffd7d00f13962c68571
|
|
BLAKE2b-256 checksum How to use checksums |
98fdd7acfde399f802e6b60c38555ffcd320e057a0a8e0b5aaf6dadb5dc125c4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/3.7.3 pkginfo/1.5.0.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.7.9
|
Release files / jsoncodable-0.1.7-py3-none-any.whl
| Download URL | jsoncodable-0.1.7-py3-none-any.whl |
|---|---|
| Size | 6.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a318a3f4d17e6c96fb3607ec24ca7c01d5d2a2ac0715718055e162c32bcd8de1
|
|
BLAKE2b-256 checksum How to use checksums |
845403f2442b2d5295ec7b8859873f05a07cfd395a7d461030a57dd71766fa25
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/3.7.3 pkginfo/1.5.0.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.7.9
|