Skip to main content

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

ntt-json-model-parser-1.0.1.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

ntt_json_model_parser-1.0.1-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

Details for the file ntt-json-model-parser-1.0.1.tar.gz.

File metadata

  • Download URL: ntt-json-model-parser-1.0.1.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

Hashes for ntt-json-model-parser-1.0.1.tar.gz
Algorithm Hash digest
SHA256 26d5389a0102ba101cb3e1c18ef552dd0baa47624ef3284077d0baac3c5188b5
MD5 e09265df137db2c240419e91593144e0
BLAKE2b-256 14b1f674be321570291db16a456b905d68abaf91162d5c155df7e3283cc27f78

See more details on using hashes here.

File details

Details for the file ntt_json_model_parser-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for ntt_json_model_parser-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 781ab7d5e4dafc4504b4339adebe96171f43625c57809800f7ede371cc29a90b
MD5 4c26e5aa2308be598a27ebacd535a665
BLAKE2b-256 f782bc7d65cf3678a4016928d555bd6bdf5053d5d8e28c95855a30dccca8544f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page