Skip to main content

Allows to serialize python classes into JSON objects and deserialize JSON objects into python classes

Project description

JSON Transform

Json Transform allows you to simply serialize your Python objects into a JSON format and vice versa.

New? Here is some help:

Example

Setup your object.

from jsontransform import field, JsonObject


class Customer(JsonObject):
    def __init__(self):
        self._first_name = ""
        self._age = 0

    # set a custom name for the field becuase by default it will be the function name
    @property
    @field("firstName")
    def first_name(self):
        return self._first_name

    @first_name.setter
    def first_name(self, value):
        self._first_name = value

    @property
    @field()
    def age(self):
        return self._age

    @age.setter
    def age(self, value):
        self._age = value

Instantiate the object and serialize it.

new_customer = Customer()
new_customer.first_name = "Peter"
new_customer.age = 1

# get a dict representation of the object
# result: {"firstName": "Peter", "age": 1}
new_customer.to_json_dict()

# we can also write the object directly into a file
with open("new_customer.json", "w") as f:
    new_customer.to_json_file(f)

Deserialize a JSON file into your object.

JSON file (customer.json):

{
  "firstName": "Dennis",
  "age": 70
}

Code:

# we load our customer object
with open("customer.json", "r") as f:
    customer = Customer.from_json_file(f)

customer.age
# result: 70

customer.first_name
# result: Dennis

More

Check out the documentation.

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

json-transform-0.1.5.tar.gz (9.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

json_transform-0.1.5-py2-none-any.whl (11.4 kB view details)

Uploaded Python 2

File details

Details for the file json-transform-0.1.5.tar.gz.

File metadata

  • Download URL: json-transform-0.1.5.tar.gz
  • Upload date:
  • Size: 9.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/2.7.15rc1

File hashes

Hashes for json-transform-0.1.5.tar.gz
Algorithm Hash digest
SHA256 b3011baf2c3d14d3ba85a32ceff4f97653e14c58fad0c7bffb6465912831f2a3
MD5 6c8cf6a2054689d392794f1d313e4783
BLAKE2b-256 204906d8343290ad37707f7653120fd4f1a0a402c7688b261e7d24d2b3ec73f0

See more details on using hashes here.

File details

Details for the file json_transform-0.1.5-py2-none-any.whl.

File metadata

  • Download URL: json_transform-0.1.5-py2-none-any.whl
  • Upload date:
  • Size: 11.4 kB
  • Tags: Python 2
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/2.7.15rc1

File hashes

Hashes for json_transform-0.1.5-py2-none-any.whl
Algorithm Hash digest
SHA256 aed27e918907ca1130179c9ebc69fa970c8a4141f07e703f20b935f2d752c9cf
MD5 8c02a066bb07dd74d75f1177b263a75d
BLAKE2b-256 b9cdcd06580676fc4c7b2d1c1d5a74db51ee7ddbcbfabe745fa6228addb08020

See more details on using hashes here.

Supported by

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