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, 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
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.7.tar.gz
(5.1 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file jsoncodable-0.1.7.tar.gz.
File metadata
- Download URL: jsoncodable-0.1.7.tar.gz
- Upload date:
- Size: 5.1 kB
- Tags: Source
- Uploaded using 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
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1c4a51987545694a61c14d08dd4ff9abbcf80b9f1d675ffd7d00f13962c68571
|
|
| MD5 |
834763d94cb6c728ee5d38408b1df89b
|
|
| BLAKE2b-256 |
98fdd7acfde399f802e6b60c38555ffcd320e057a0a8e0b5aaf6dadb5dc125c4
|
File details
Details for the file jsoncodable-0.1.7-py3-none-any.whl.
File metadata
- Download URL: jsoncodable-0.1.7-py3-none-any.whl
- Upload date:
- Size: 6.4 kB
- Tags: Python 3
- Uploaded using 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
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a318a3f4d17e6c96fb3607ec24ca7c01d5d2a2ac0715718055e162c32bcd8de1
|
|
| MD5 |
52e0f4a5f83f0c09288e996eddfb079c
|
|
| BLAKE2b-256 |
845403f2442b2d5295ec7b8859873f05a07cfd395a7d461030a57dd71766fa25
|