# 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.
```python
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
```python
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
```
```python
dictObjectData = {
"strName": "Thao Nguyen The",
"nAge": 23,
}
perFirstStudent: Person = Parser.DeSerializeFromDict(Person, dictObjectData)
dictSerializedData = Parser.SerializeToDict(perFirstStudent)
```
The same result for the `Serialize` method
Raw data
{
"_id": null,
"home_page": "https://github.com/threezinedine/ntt-json-model-parser",
"name": "ntt-json-model-parser",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "json,parser,object",
"author": "threezinedine",
"author_email": "threezinedine@email.com",
"download_url": "https://files.pythonhosted.org/packages/a9/4f/e8fa11776e5a4d5053d38a29f9b88c7d270cb7c887a39e68fa27c82b8c96/ntt-json-model-parser-1.1.3.tar.gz",
"platform": null,
"description": "# ntt-json-model-parser\r\nThe project for parsing the data from .json file (use json format) to a object in Python\r\n\r\n## Usage\r\n\r\nFirstly, define the model.\r\n\r\n```python\r\nfrom ntt_json_model_parser import Parser, ModelProperty, Model, Property\r\n\r\n\r\n\r\n@Model\r\nclass Lecture:\r\n def __init__(self) -> None:\r\n self._strName = \"\"\r\n self._nAttempts = 0\r\n\r\n @Property\r\n def strName(self) -> str:\r\n return self._strName\r\n\r\n @Property\r\n def nAttempts(self) -> int:\r\n return self._nAttempts\r\n\r\n@Model\r\nclass Person:\r\n def __init__(self) -> None:\r\n self._strName = \"\"\r\n self._nAge = 0\r\n\r\n self._lecLecture : Lecture = Lecture()\r\n\r\n @Property\r\n def strName(self) -> str:\r\n return self._strName\r\n\r\n @Property\r\n def nAge(self) -> int:\r\n return self._nAge\r\n\r\n @ModelProperty(Lecture)\r\n def lecLecture(self) -> Lecture:\r\n return self._lecLecture\r\n```\r\n\r\nThen using\r\n\r\n```python\r\ndictObjectData = {\r\n \"strName\": \"Thao Nguyen The\",\r\n \"nAge\": 23,\r\n \"lecLecture\": None\r\n}\r\n\r\nperFirstStudent: Person = Parser.DeSerializeFromDict(Person, dictObjectData)\r\n\r\n# The student will have the name: `Nguyen The Thao` and the lecture with default value\r\n\r\n```\r\n\r\n\r\n```python\r\ndictObjectData = {\r\n \"strName\": \"Thao Nguyen The\",\r\n \"nAge\": 23,\r\n}\r\n\r\nperFirstStudent: Person = Parser.DeSerializeFromDict(Person, dictObjectData)\r\n\r\ndictSerializedData = Parser.SerializeToDict(perFirstStudent)\r\n```\r\n\r\nThe same result for the `Serialize` method\r\n\r\n",
"bugtrack_url": null,
"license": "",
"summary": "Convert data from .json file to python object",
"version": "1.1.3",
"project_urls": {
"Homepage": "https://github.com/threezinedine/ntt-json-model-parser",
"Source": "https://github.com/threezinedine/ntt-json-model-parser",
"Tracker": "https://github.com/threezinedine/ntt-json-model-parser/issues"
},
"split_keywords": [
"json",
"parser",
"object"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "c1b2ab0596495108b7d09f83450d3ab6b569fc540885c6642458c6e53d764955",
"md5": "44271d96804e3de30f1dd87db0deb7f0",
"sha256": "f0db403c2a1d1512d20af1039330284a6ef2f4a4eb4c439d9d46bc2e8d76c106"
},
"downloads": -1,
"filename": "ntt_json_model_parser-1.1.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "44271d96804e3de30f1dd87db0deb7f0",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 9784,
"upload_time": "2023-11-16T13:31:22",
"upload_time_iso_8601": "2023-11-16T13:31:22.820683Z",
"url": "https://files.pythonhosted.org/packages/c1/b2/ab0596495108b7d09f83450d3ab6b569fc540885c6642458c6e53d764955/ntt_json_model_parser-1.1.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "a94fe8fa11776e5a4d5053d38a29f9b88c7d270cb7c887a39e68fa27c82b8c96",
"md5": "082d91c699717278354f47790f3e1786",
"sha256": "42b3610e43a891cc142b301c2a8aa7f1f1526a3d09257533ec04863489937384"
},
"downloads": -1,
"filename": "ntt-json-model-parser-1.1.3.tar.gz",
"has_sig": false,
"md5_digest": "082d91c699717278354f47790f3e1786",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 6841,
"upload_time": "2023-11-16T13:31:24",
"upload_time_iso_8601": "2023-11-16T13:31:24.541805Z",
"url": "https://files.pythonhosted.org/packages/a9/4f/e8fa11776e5a4d5053d38a29f9b88c7d270cb7c887a39e68fa27c82b8c96/ntt-json-model-parser-1.1.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-11-16 13:31:24",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "threezinedine",
"github_project": "ntt-json-model-parser",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "ntt-json-model-parser"
}