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.
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
- Check out the documentation.
- Check out the history
Project details
Release history Release notifications | RSS feed
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.9.1.tar.gz
(11.7 kB
view hashes)
Built Distribution
Close
Hashes for json_transform-0.1.9.1-py2-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e92e06038a77aff5fc8695dac56860e0a6bd29a8e2945f187d38b1a0aa261228 |
|
MD5 | de9034b19cbda9c3b87b5494b7ba3bea |
|
BLAKE2b-256 | a053ee402d6492f3cf73f56585213138e435d0aeb4d94a27fccb6314cbce4a1a |