Skip to main content

Python library for serializing any arbitrary object graph into JSON

Project description

Python library for serializing any arbitrary object graph into JSON. It can take almost any Python object and turn the object into JSON. Additionally, it can reconstitute the object back into Python.

>>> import jsonpickle
>>> from samples import Thing

Create an object.

>>> obj = Thing('A String')
>>> print
A String

Use jsonpickle to transform the object into a JSON string.

>>> pickled = jsonpickle.encode(obj)
>>> print pickled
{"py/object": "samples.Thing", "name": "A String", "child": null}

Use jsonpickle to recreate a Python object from a JSON string

>>> unpickled = jsonpickle.decode(pickled)
>>> str(
'A String'


Loading a JSON string from an untrusted source represents a potential security vulnerability. jsonpickle makes no attempt to sanitize the input.

The new object has the same type and data, but essentially is now a copy of the original.

>>> obj == unpickled
>>> ==
>>> type(obj) == type(unpickled)

If you will never need to load (regenerate the Python class from JSON), you can pass in the keyword unpicklable=False to prevent extra information from being added to JSON.

>>> oneway = jsonpickle.encode(obj, unpicklable=False)
>>> print oneway
{"name": "A String", "child": null}

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 jsonpickle, version 0.4.0
Filename, size File type Python version Upload date Hashes
Filename, size jsonpickle-0.4.0.tar.gz (25.4 kB) File type Source Python version None Upload date Hashes View

Supported by

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