Skip to main content

Json raw data to object

Project description

jsontofu.png

Usage

@dataclass
class Data:
    str_data: str
    int_data: int

@dataclass
class DictData:
    str_data: str
    dict_data: Optional[Dict]

@dataclass
class RecursiveData:
    str_data: str
    dict_data: Data

json_data1 = {
    'str_data': 'test',
    'int_data': 123
}

json_data2 = {,
    'str_data': 'test',
    'dict_data': {'key1': 123, 'key2': 456}
}

json_data3 = {,
    'str_data': 'test',
    'dict_data': {'str_data': 'test', 'int_data': 456}
}

print(jsontofu.decode(json_data1, Data)) # Data(str_data="test", int_data=123)

print(jsontofu.decode(json_data2, DictData)) # DictData(str_data="test", dict_data={'key1': 123, 'key2': 456})

print(jsontofu.decode(json_data3, RecursiveData)) # RecursiveData(str_data="test", Data(str_data="test", int_data=456)

Installation

pip install git+git://github.com/rondou/jsontofu.git

or

pipenv install 'git+ssh://git@github.com/rondou/jsontofu.git#egg=jsontofu'

Development

pipenv install
pipenv install -d
pipenv run "pytest -s"

Coverage

pipenv run 'pytest tests --cov=jsontofu'

Project details


Download files

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

Filename, size & hash SHA256 hash help File type Python version Upload date
jsontofu-0.0.7.tar.gz (4.7 kB) Copy SHA256 hash SHA256 Source None

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page