Skip to main content
Help the Python Software Foundation raise $60,000 USD by December 31st!  Building the PSF Q4 Fundraiser


Project description


python_version PyPI downloads/month


Easily create object from any dict and dict from any object


pip install jsoncodable
# or
pip3 install jsoncodable


from jsoncodable import *
import json

# ---------------------------------------- Any object to json dict ---------------------------------------- #

class Test1:
    def __init__(self, value: int):
        self.value1 = value
        self.value2 = value * 2
        self.values = [self.value1, self.value2]

class Test2(JSONCodable):
    def __init__(self, value: int):
        self.test1 = Test1(value)

test2 = Test2(5)
# prints:
# {'test1': <__main__.Test1 object at 0x1018199d0>}

print(json.dumps(test2.json, indent=4))
# or
# both will print:
# {
#     "test1": {
#         "value1": 5,
#         "value2": 10,
#         "values": [
#             5,
#             10
#         ]
#     }
# }

# ---------------------------------------- Any json dict to object ---------------------------------------- #

class Test3(JSONCodable):

json_str = '{"name": "John Smith", "hometown": {"name": "New York", "id": 123}}'

# prints:
# JSONCodable(name='John Smith', hometown=JSONCodable(name='New York', id=123))

# prints:
# JSONCodable(name='John Smith', hometown=JSONCodable(name='New York', id=123))

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for jsoncodable, version 0.0.6
Filename, size File type Python version Upload date Hashes
Filename, size jsoncodable-0.0.6-py3-none-any.whl (3.9 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size jsoncodable-0.0.6.tar.gz (2.8 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page