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.1.1.tar.gz
.
File metadata
- Download URL: ntt-json-model-parser-1.1.1.tar.gz
- Upload date:
- Size: 6.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 | fb7a58b63da70f8a045e9026ad0a55b76a6f881ba43590a1da288cd77c407a96 |
|
MD5 | a9e03653f6840b7d511af906770af6eb |
|
BLAKE2b-256 | 48f350b451d9bf5e8b6b84f39e935f09379b06c3d598aecabea44fc198cfff77 |
File details
Details for the file ntt_json_model_parser-1.1.1-py3-none-any.whl
.
File metadata
- Download URL: ntt_json_model_parser-1.1.1-py3-none-any.whl
- Upload date:
- Size: 9.7 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 | 421d9e8fed7479d3503f91b3bbd895206bcb5a7d0b80b6e52d2d6e279f31aef5 |
|
MD5 | 070675ce7a801c4de58edc9f764c964d |
|
BLAKE2b-256 | 071239f7d8586047807d1c2651ce41736bad3c7626172380b53b4cf2a209ca77 |