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 obj.name
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(unpickled.name)
'A String'

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}

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

jsonpickle-0.4.0.tar.gz (25.4 kB view details)

Uploaded Source

File details

Details for the file jsonpickle-0.4.0.tar.gz.

File metadata

  • Download URL: jsonpickle-0.4.0.tar.gz
  • Upload date:
  • Size: 25.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for jsonpickle-0.4.0.tar.gz
Algorithm Hash digest
SHA256 546cd22d361ef7019f60e2fb6dd032c1e78d731fac962bda7c15806e6c0285a8
MD5 63916228294218ca6e53fd1b16b626fa
BLAKE2b-256 7d2bd9c2b502976a56fdda4dfc58c04a47fdf9cad8da1cea5fe503fe107eacb2

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