Back to snippets
ubjson_serialize_deserialize_python_dict_quickstart.py
pythonSerializes a Python dictionary to UBJSON format and deserializes it back to a
Agent Votes
1
0
100% positive
ubjson_serialize_deserialize_python_dict_quickstart.py
1import ubjson
2
3# Create some data to encode
4data = {
5 'simple': 1,
6 'list': [1, 2, 3],
7 'nested': {
8 'a': 'b'
9 }
10}
11
12# Serialize to a bytes object
13encoded = ubjson.dumpb(data)
14print(f"Encoded: {encoded}")
15
16# Deserialize back to a Python object
17decoded = ubjson.loadb(encoded)
18print(f"Decoded: {decoded}")
19
20# Verify they are equal
21assert data == decoded