I have seen the terms "deserialize" and "serialize" with JSON. What do they mean?
(I'm new in JSON. Now, I need to use JSON for my Flash ActionScript 3.0. So I found one lib for JSON)
I have seen the terms "deserialize" and "serialize" with JSON. What do they mean?
(I'm new in JSON. Now, I need to use JSON for my Flash ActionScript 3.0. So I found one lib for JSON)
In Python "serialization" does nothing else than just converting the given data structure (e.g. a
dict
) into its valid JSON pendant (object).True
will be converted to JSONstrue
and the dictionary itself will then be encapsulated in quotes.True
/False
,true
/false
json
is the standard way to do serialization:Code example:
Source: realpython.com
Try this one:
JSON is a format that encodes objects in a string. Serialization means to convert an object into that string, and deserialization is its inverse operation (convert string -> object).
When transmitting data or storing them in a file, the data are required to be byte strings, but complex objects are seldom in this format. Serialization can convert these complex objects into byte strings for such use. After the byte strings are transmitted, the receiver will have to recover the original object from the byte string. This is known as deserialization.
Say, you have an object:
serializing into JSON will convert it into a string:
which can be stored or sent through wire to anywhere. The receiver can then deserialize this string to get back the original object.
{foo: [1, 4, 7, 10], bar: "baz"}
.Explanation of Serialize and Deserialize using Python
In python, pickle module is used for serialization. So, the serialization process is called pickling in Python. This module is available in Python standard library.
Serialization using pickle
The PICKLE file (can be opened by a text editor like notepad) contains this (serialized data):
€}q (KX 6qKX 2qKX fqu.
Deserialization using pickle
Output:
{1: '6', 2: '2', 3: 'f'}