Skip to main content

Convert python objects to JSON documents and vice versa.

Project description

JSON-Transform

Codacy Badge

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

New? Here is some help:

Example

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
    @property
    @field("firstName")
    def first_name(self):
        return self._first_name

    @first_name.setter
    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
dumpd(new_customer)
# result: {"firstName": "Peter"}

# get an str with with our encoded object
dumps(new_customer)
# 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.

Code:

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'}")

customer.first_name
# result: Peter

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-1.0.0.tar.gz (7.8 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-1.0.0-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: json-transform-1.0.0.tar.gz
  • Upload date:
  • Size: 7.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/39.1.0 requests-toolbelt/0.8.0 tqdm/4.25.0 CPython/3.6.5

File hashes

Hashes for json-transform-1.0.0.tar.gz
Algorithm Hash digest
SHA256 b8ffa9a702dc8e4f9a2ca67e944143a596a64f912d85e4a7cb952b83032ae7eb
MD5 2aa689842d9204c11bf303d858a7faf3
BLAKE2b-256 cd45a473f92abb9b449d94db4af0b1162b4b280ffc0de279b53d13dcc5725683

See more details on using hashes here.

File details

Details for the file json_transform-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: json_transform-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 7.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/39.1.0 requests-toolbelt/0.8.0 tqdm/4.25.0 CPython/3.6.5

File hashes

Hashes for json_transform-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4d50b7759ace0f4fa80cc85a32eafc2e1fb426926ca439a84e17bf91edfa438a
MD5 db1de325ed4f37e166eb593e4f70991c
BLAKE2b-256 00688406a3e1d53597f6b5e6758df2dd935ae8dae0a6d95242290316dd41ec1c

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