Skip to main content

Self-Use Python lib

Project description

Self-Use Python Lib

image image

Json To Object

Usage

more info in json_test_cases

import selfusepy
obj: One = selfusepy.parse_json(jsoStr, One())

Notice

Because Python is not a strongly-typed language, so you must
assign a value when you define a variable in class, 
otherwise the parse can not get the right type of each variable, 
just like examples below 

e.g. 1

Python Class

from selfusepy.jsonparse import BaseJsonObject
class One(BaseJsonObject):

  def __init__(self):
    self.x: str = '' #  have to be assigned
    self.two: One.Two = One.Two()

  class Two(BaseJsonObject):
    def __init__(self):
      self.y: str = ''
      self.three: One.Two.Three = One.Two.Three()

    class Three(BaseJsonObject):
      def __init__(self):
        self.z: str = ''

Json str

{
  "x": "x",
  "two": {
    "y": "y",
    "three": {
      "z": "z"
    }
  }
}

e.g. 2

Python Class

from selfusepy.jsonparse import BaseJsonObject
from typing import List
class One1(BaseJsonObject):

  def __init__(self):
    self.x: str = ''
    self.two: List[One1.Two] = [One1.Two()]

  class Two(BaseJsonObject):
    def __init__(self):
      self.y: str = ''

Json str

{
  "x": "x",
  "two": [
    {
      "y": "y1"
    },
    {
      "y": "y2"
    }
  ]
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for selfusepy, version 0.0.3
Filename, size File type Python version Upload date Hashes
Filename, size selfusepy-0.0.3.tar.gz (9.6 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page