jsonpickle 0.2.0
Python library for serializing any arbitrary object graph into JSON
Latest Version: 0.4.0
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 jsonpickle.tests.classes import Thing
Create an object.
>>> obj = Thing('A String')
>>> print obj.name
A String
Use jsonpickle to transform the object into a JSON string.
>>> pickled = jsonpickle.encode(obj)
>>> print pickled
{"py/object": "jsonpickle.tests.classes.Thing", "name": "A String", "child": null}
Use jsonpickle to recreate a Python object from a JSON string
>>> unpickled = jsonpickle.decode(pickled) >>> str(unpickled.name) 'A String'
Warning
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 False >>> obj.name == unpickled.name True >>> type(obj) == type(unpickled) True
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}
- Author: John Paulett
- Home Page: http://code.google.com/p/jsonpickle/
- Keywords: json pickle,json,pickle,marshal,serialization,JavaScript Object Notation
- License: BSD
- Platform: POSIX,Windows
- Categories
- Package Index Owner: johnpaulett
- DOAP record: jsonpickle-0.2.0.xml
