jsonpickle is a Python library for serialization and deserialization of complex Python objects to and from JSON. The standard Python libraries for encoding Python into JSON, such as the stdlib’s json, simplejson, and demjson, can only handle Python primitives that have a direct JSON equivalent (e.g. dicts, lists, strings, ints, etc.). jsonpickle builds on top of these libraries and allows more complex data structures to be serialized to JSON. jsonpickle is highly configurable and extendable–allowing the user to choose the JSON backend and add additional backends.
Python library for serializing any arbitrary object graph into JSON.
jsonpickle can execute arbitrary Python code. Do not load jsonpickles from untrusted / unauthenticated sources.
jsonpickle can take almost any Python object and turn the object into JSON. Additionally, it can reconstitute the object back into Python.
The object must be accessible globally via a module and must inherit from object (AKA new-style classes).
Create an object:
class Thing(object): def __init__(self, name): self.name = name obj = Thing('Awesome')
Use jsonpickle to transform the object into a JSON string:
import jsonpickle frozen = jsonpickle.encode(obj)
Use jsonpickle to recreate a Python object from a JSON string:
thawed = jsonpickle.decode(frozen)
The new object has the same type and data, but essentially is now a copy of the original.
assert obj.name == thawed.name
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) result = jsonpickle.decode(oneway) assert obj.name == result['name'] == 'Awesome'
$ pip install -U jsonpickle
jsonpickle has no required dependencies (it uses the standard library’s
json module by default).
You can also download or checkout the latest code and install from source:
$ python setup.py install
- jsonpickle API
jsonpickle– High Level API
- Low Level API
Please join our mailing list. You can send email to firstname.lastname@example.org.
Check https://github.com/jsonpickle/jsonpickle for project updates.
- Change Log
- Version 1.0 - September 1, 2018
- Version 0.9.6 - February 9, 2018
- Version 0.9.5 - July 16, 2017
- Version 0.9.4 - January 10, 2017
- Version 0.9.3 - March 9, 2016
- Version 0.9.2 - March 20, 2015
- Version 0.9.1 - March 15, 2015
- Version 0.9.0 - January 16, 2015
- Version 0.8.0 - September 6, 2014
- Version 0.7.2 - August 6, 2014
- Version 0.7.1 - May 6, 2014
- Version 0.7.0 - March 15, 2014
- Version 0.6.1 - August 25, 2013
- Version 0.6.0 - August 24, 2013
- Version 0.5.0 - August 22, 2013
- Version 0.4.0 - June 21, 2011
- Version 0.3.1 - December 12, 2009
- Version 0.3.0 - December 11, 2009
- Version 0.2.0 - January 10, 2009
- Version 0.1.0 - August 21, 2008
- Version 0.0.5 - July 21, 2008
- Version 0.0.3
- Version 0.0.2
- Version 0.0.1