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
class Lecture:
def __init__(self) -> None:
self.strName = ""
self.nAttempts = 0
class Person:
def __init__(self) -> None:
self.strName = ""
self.nAge = 0
self._lecLecture : Lecture = Lecture()
@ModelProperty
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
Close
Hashes for ntt-json-model-parser-1.0.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5ff507967aea05d384b13ad4ace048ef8d48d98e5ecae9d90e95c305759e3970 |
|
MD5 | 65f6d524d6ae9c0315d7e60e02244387 |
|
BLAKE2b-256 | 55827127745ab9ab1a72a9d15dff9c57f94c0ff63cb1bf8ea5944fcc7cc2d3a9 |
Close
Hashes for ntt_json_model_parser-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 375b11746f24c256623a025e228ff7036e7e01c46c569f2328fe1727cd7e59f0 |
|
MD5 | d35c9c58512cb8941f0b7850862423bb |
|
BLAKE2b-256 | d91915a875895c8b6e306ba85afe5b6f615a1293f8ffc7fbe218101f1e982478 |