jsonpickle is a Python library for serialization and deserialization of complex Python objects to and from JSON. It extends standard JSON encoders to handle more complex data structures than what Python's `json` module natively supports. As of version 4.1.1, the project is actively maintained with a regular release cadence.
pip install jsonpickleVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates encoding a custom Python object (a dataclass instance) into a JSON string and then decoding it back into a Python object using `jsonpickle.encode` and `jsonpickle.decode`.
NEVER deserialize data from untrusted sources. If processing untrusted input, use safer serialization methods like the standard `json` module, define explicit schemas, or sign data with an HMAC to ensure integrity.
Upgrade to Python 3.8 or newer to use `jsonpickle` v4.x.
Ensure you are not explicitly setting `safe=False` when dealing with untrusted input. The default `safe=True` is recommended for security. If you need to decode old data, re-pickle it with a newer version.
Avoid direct usage of `jsonpickle.compat` and its functions. Review `CHANGES.rst` for specific function deprecations that might affect your code.
Review your code for direct calls to functions within `jsonpickle.util` or reliance on `jsonpickle.ext.yaml` being automatically registered. Migrate away from these as v5.0.0 approaches.
Run `pip install jsonpickle` to install the library.
Ensure the custom class definition is imported and available in the global scope when calling `jsonpickle.decode()`. If `unpicklable=False` was used during encoding, `jsonpickle` cannot reconstruct the original object type, and you will receive a dictionary representation.
Never use `jsonpickle.decode()` on data from untrusted or unvalidated sources. For untrusted data, use standard JSON parsing (`json.loads`) and validate against explicit schemas. If using `jsonpickle` is necessary, ensure `safe=True` is passed to `decode()` and understand its limitations.
Upgrade `jsonpickle` to the latest version. If the problem persists, try upgrading the conflicting library (e.g., `requests`). As a workaround, you might convert `OrderedDict` instances to standard `dict` objects before serialization if their order is not critical for deserialization outside of the original context.