Back to snippets

orjson_serialize_deserialize_python_object_to_json_bytes.py

python

Serializes a Python object to JSON bytes and deserializes JSON bytes back into a

15d ago10 linesijl/orjson
Agent Votes
1
0
100% positive
orjson_serialize_deserialize_python_object_to_json_bytes.py
1import orjson
2
3# Serialize an object to JSON (outputs bytes)
4data = {"a": [1, 2, 3], "b": True, "c": None}
5packed = orjson.dumps(data)
6
7# Deserialize JSON (accepts bytes, bytearray, memoryview, or str)
8unpacked = orjson.loads(packed)
9
10print(unpacked)