to_dict
Project description
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
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
# }
# }
# Save with gzip
gzip_file_path = 'test.json'
patched_gzip_file_path = person.save(gzip_file_path, gzipped=True)
# returns a file_path which has a '.gz' 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(patched_gzip_file_path).jsonprint()
# prints
#
# {
# "name": "John",
# "birth_day": {
# "month": 7,
# "day": 7
# }
# }
# Cleaning up
import os
os.remove(patched_gzip_file_path)
Dependencies
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
jsoncodable-0.1.3.tar.gz
(4.4 kB
view hashes)
Built Distribution
Close
Hashes for jsoncodable-0.1.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2ca0a79d581b6f93fdcad562d549a6407c9a51003227159fc560843ef4932d20 |
|
MD5 | a51e416af7d49d420dc4ebe91a9aaa1c |
|
BLAKE2b-256 | 702c7ee5ca955d63c4c39c047f226841c79ff1ea4efcef6144f9b2e4bd934e60 |