jsonpickle

4.1.1 · active · verified Sun Mar 29

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.

Warnings

Install

Imports

Quickstart

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`.

import jsonpickle
from dataclasses import dataclass

@dataclass
class MyObject:
    name: str
    value: int

# Create an object
original_obj = MyObject(name="Example", value=123)

# Encode the object to a JSON string
encoded_json = jsonpickle.encode(original_obj)
print(f"Encoded JSON: {encoded_json}")

# Decode the JSON string back to a Python object
decoded_obj = jsonpickle.decode(encoded_json)

# Verify the decoded object
assert decoded_obj == original_obj
print(f"Decoded object: {decoded_obj}")

view raw JSON →