Convert data from .json file to python object
Project description
ntt-json-model-parser
The project for parsing the data from .json file (use json format) to a object in Python
Usage
Firstly, define the model.
from ntt_json_model_parser import Parser, ModelProperty, Model, Property
@Model
class Lecture:
def __init__(self) -> None:
self._strName = ""
self._nAttempts = 0
@Property
def strName(self) -> str:
return self._strName
@Property
def nAttempts(self) -> int:
return self._nAttempts
@Model
class Person:
def __init__(self) -> None:
self._strName = ""
self._nAge = 0
self._lecLecture : Lecture = Lecture()
@Property
def strName(self) -> str:
return self._strName
@Property
def nAge(self) -> int:
return self._nAge
@ModelProperty(Lecture)
def lecLecture(self) -> Lecture:
return self._lecLecture
Then using
dictObjectData = {
"strName": "Thao Nguyen The",
"nAge": 23,
"lecLecture": None
}
perFirstStudent: Person = Parser.DeSerializeFromDict(Person, dictObjectData)
# The student will have the name: `Nguyen The Thao` and the lecture with default value
dictObjectData = {
"strName": "Thao Nguyen The",
"nAge": 23,
}
perFirstStudent: Person = Parser.DeSerializeFromDict(Person, dictObjectData)
dictSerializedData = Parser.SerializeToDict(perFirstStudent)
The same result for the Serialize
method
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file ntt-json-model-parser-1.0.2.tar.gz
.
File metadata
- Download URL: ntt-json-model-parser-1.0.2.tar.gz
- Upload date:
- Size: 4.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4b76ec863a0b8f611d1a627a21c08ac65b41f5b3908d76976549bcbf7853baae |
|
MD5 | 50c4a2e69b04145bb53388be32857a4c |
|
BLAKE2b-256 | 692c86328b4e9524119490b9da3edefa27169ecd8cbd2afe2c45e4213ab7a718 |
File details
Details for the file ntt_json_model_parser-1.0.2-py3-none-any.whl
.
File metadata
- Download URL: ntt_json_model_parser-1.0.2-py3-none-any.whl
- Upload date:
- Size: 6.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 76288b3bd12e611af890eba4c15f54cb2232c5f431f56b7e8a98243c601c94cf |
|
MD5 | f777b9243e93832329286c18ec6074ec |
|
BLAKE2b-256 | 6fd2ec8ce8761ce175799e04c8e7d804be44e94a9bd1ce2d90f2c3ec4dae551c |