Skip to main content

Convert python objects to JSON documents and vice versa.

Project description


Codacy Badge

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

New? Here is some help:


Setup your object/entity.

from jsontransform import field, JSONObject

class Customer(JSONObject):
    def __init__(self):
        self._first_name = ""

    # set a custom name for the field because by default it will be the function name
    def first_name(self):
        return self._first_name

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

Instantiate the object and encode it to a JSON document.

from jsontransform import dumpd, dump, dumps

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

# get a dict representation of the object
# result: {"firstName": "Peter"}

# get an str with with our encoded object
# result: '{"firstName": "Peter"}'

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

JSON file (new_customer.json):

  "firstName": "Peter"

Decode a JSON document.


from jsontransform import load, loadd, loads

# we can decode our customer object from a JSON file
with open("new_customer.json", "r") as f:
    customer = load(f)

# or a dict
customer = loadd({"firstName": "Peter"})

# or an str as well
customer = loads("{'firstName': 'Peter'}")

# result: Peter


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 json-transform, version 1.0.1
Filename, size File type Python version Upload date Hashes
Filename, size json_transform-1.0.1-py3-none-any.whl (7.3 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size json-transform-1.0.1.tar.gz (7.7 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page