Skip to main content

Convert python objects to JSON objects and vice versa.

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.

from jsontransform import Serializer

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

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

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

Deserialize a JSON file into your object.

JSON file (customer.json):

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

Code:

from jsontransform import Deserializer

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

customer.age
# result: 70

customer.first_name
# result: Dennis

More

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.4.1.tar.gz (6.6 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.4.1-py2-none-any.whl (6.8 kB view details)

Uploaded Python 2

File details

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

File metadata

  • Download URL: json-transform-0.4.1.tar.gz
  • Upload date:
  • Size: 6.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/39.2.0 requests-toolbelt/0.8.0 tqdm/4.25.0 CPython/2.7.15

File hashes

Hashes for json-transform-0.4.1.tar.gz
Algorithm Hash digest
SHA256 620aa52800e7b68946eae278a4a57c29f797fa6a8f7ff7aea7de8d052b38f789
MD5 09b4d0b815777ae3f695d95e7dbaab65
BLAKE2b-256 8e5179d545436fa8322267e9cf9d102675d2711c01d7b00bec37d04cbf18046d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: json_transform-0.4.1-py2-none-any.whl
  • Upload date:
  • Size: 6.8 kB
  • Tags: Python 2
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/39.2.0 requests-toolbelt/0.8.0 tqdm/4.25.0 CPython/2.7.15

File hashes

Hashes for json_transform-0.4.1-py2-none-any.whl
Algorithm Hash digest
SHA256 f3faaf8795dccc0ba8b00d9e57ddc455651eabe89a038edfc4405f73f94abb49
MD5 dc2d9e3889652f48cdfee115c4bf5c85
BLAKE2b-256 81bb7f5b277758e9ddf35be40948769f4cedb097e93b4eb44c8d51c6f231a874

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