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.1.2.tar.gz (6.9 kB view details)

Uploaded Source

Built Distribution

ntt_json_model_parser-1.1.2-py3-none-any.whl (9.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ntt-json-model-parser-1.1.2.tar.gz
  • Upload date:
  • Size: 6.9 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.1.2.tar.gz
Algorithm Hash digest
SHA256 e1a10c0835c529b081892b058e8bb8663193e4f8522b34907f22d4ccc44d1f37
MD5 0c419484d3b10c5f3f8d9ca124c47543
BLAKE2b-256 9c4313a7fbaab6063f18ec7d9a8baf2169444bb862b11963c920c4f2400fad05

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ntt_json_model_parser-1.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 5274226cb00b5f9d95dc7931a0d2521c4c6985d6d5eaab82ac91769af0806aa1
MD5 3f431697858c36dc6d01107f69d502ef
BLAKE2b-256 c3581bf30cf489466d22bdfe4334a1a3e008ffe0fe66aa45c90904c1b8019d96

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