Data Exchange formats:
Please note that this blog post is an adaptation of an article released in Dr Dobb's.
Data serialization is always a simple problem to address.
There are so many options that are available now days. Yet the actual need
remains the same. Does that means that all these standards are failing to
deliver what is actually needed. Let’s take a look.
Data serialization in early days: Back in old days, data serialization
was used to handle using binary protocols, which was unfortunately, not human
readable format. Moreover these protocols are custom defined on ad-hoc basis.
The sender and receiver had to agree on an agreement with respect to the fields
and its associated data. Eventually these schemes made a way, partially, to
emerge as a standard. Such a known standard is ASN.1.
OS addition: Evolution of operating systems and their inter
communication, raised a new problem. Servers that lives in UNIX world need to
exchange data in some way. Added complexity to the problem is how to exchange
binary data when systems are using different endian system? The resulting, XDRformat, proposed by Sun, solves this key problem. It was quiet successful and
still found today in NFS.
Internet: The age of internet starts from mid-1990s, and
hence requires a need for new standard which is human readable (XDR is not
human readable), hence SGML- the markup super class, from which HTML is
derived. In 1998, SGML was reworked, and evolved into another standard named as
XML, which is till now considered to be most successful profile of SGML. By the
end of the century, it was already in wide use. All languages (major or minor)
had XML lib, and the format is been used whenever or wherever any kind of human
readable data representation was required. It was so popular that it moved to
the areas where it was never meant or intended to be, such as text markup, for
ex DocBook (many thanks to XSLT!!).
Popularity of XML has hindered several drawbacks. Its
drawbacks list starts from complexity of schema to performance. Some performance
evangelists even believe that more than 40% of CPU cycles have been consumed
while encoding or decoding the XML.
JavaScript evolution and JSON:
Evolution of javascript and its revolution has reshaped the
entire arena, hence leads to another standard known as JSON. Standard JSON can
be read as javascript, which is also being widely supported with many tools and
lib. Although been popular and widely used, JSON suffers from some desirable
traits. One of such traits is comments, JSON doesn’t support comments. Another
one, there is no support for date data type. Above all it cannot represent the
relational data.
These drawbacks have already led to its variants like BSON,
devised by 10gen and used in their Mongo DB NO SQL database.
JSON extension:
Frustration with JSON has spurred a new revolution of examination
and proposal of entirely new schemes. Such a most interesting scheme is TOML from Tom-preston-werner, a co-founder of GitHub. It uses a different notational
scheme but contains the same brevity of JSON. TOML represents its structure
like configuration files with key value pairs specified one per line and
grouped by square bracketed item names. At a go you can feel a slight similarity
with the .ini files popularized by Microsoft. TOML is not the only alternative
under development. Another such is Protocol buffers, developed by Google,
considered to be low-overhead, high speed data exchange format.
YAML: This discussion can’t be ended without discussing
about YAML. YAML is considered to be, most remarkably, big standard (almost 80
pages), but concise in practice and highly readable. It borrows the Python's
use of whitespace to indicate the start and end of blocks or subblocks. It avoids
quotation marks, brackets, braces and open/close tags. It can reference to the
element which is defined previously. Repeated element can be refer by creating
an alias. Above all it supports standard data types & can map easily to
lists, map, and hashes. Till now, it is supported by a wide variety of
languages and its supporting libs.
For further reference, please check the wiki entry for comparisonbetween different formats.