DEV Community


What is the difference between parsing and serialization?

・1 min read

So, I've come across both terms and I don't understand how serialization is different than parsing. They seem to be different as I've never read about both in the same context but they seem to be similar as they do roughly the same thing, I think.

Discussion (4)

ahferroin7 profile image
Austin S. Hemmelgarn • Edited

Serialization is the process of converting a data structure into a format that it can be safely stored or transmitted and the recreated from the stored or transmitted format. It's usually used to refer to applying this process to complex data structures like trees, objects, or graphs, as they don't inherently lend themselves to being transmitted as a simple string of binary data. Converting an in-memory object to JSON or XML is an example of serialization.

Parsing, on the other hand, takes a stream of (structured) data and then does something based on the contents of that stream, usually either creating an in-memory structure based on it, or executing a sequence of operations based on it. Deserialization (the reverse process of serialization) is a particular type of parsing, it takes serialized data and recreates the original data structure from it. However, you can do many other types of parsing. Compiling source code is also a type of parsing (together with then serializing the result of the parsing as machine code or assembly), as is linting or formatting code, doing static analysis of it, and many other things you would do to it using tools. So is decompressing a compressed file or listing the contents of an archive.

Note that both terms are very generic. Parsing routines and data serialization routines tend to be rather specific to the exact purpose they were designed for.

brandinchiu profile image
Brandin Chiu

+1 for using deserialization as a great example of parsing.

deciduously profile image
Ben Lovy • Edited

Parsing is the process of reading input and understanding it semantically as data structures. Serialization is the process of taking data structures and writing them to a textual format.

Deserialization is the opposite process, of taking a text format and building a data structure. The difference to parsing is that when deserializing, your data is still formatted. You expect this text format to adhere to a standard. When parsing, you are writing logic to turn one format of input into another, deserialization in my understanding is more just exchanging between alternate representations of the same data format.

jdforsythe profile image
Jeremy Forsythe

Serialization = encoding. Deserialization = decoding = parsing

Forem Open with the Forem app