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
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()
Person.load(person.json).jsonprint()
import os
json_file_path = 'test.json'
for c in CompressionAlgorithm:
compressed_file_path = person.save(json_file_path, compression=c)
Person.load(compressed_file_path).jsonprint()
os.remove(compressed_file_path)
Dependencies
jsonpickle, noraise