2. DATA SERIALIZATIONDATA SERIALIZATION
It is the process of taking some information from one
system, churning it into a format that other systems
can read, and then passing it along to those other
systems.
3. DATA SERIALIZATION FORMATS MOSTLYDATA SERIALIZATION FORMATS MOSTLY
FALL INTO TWO CATEGORIES:FALL INTO TWO CATEGORIES:
4. DATA SERIALIZATION FORMATS MOSTLYDATA SERIALIZATION FORMATS MOSTLY
FALL INTO TWO CATEGORIES:FALL INTO TWO CATEGORIES:
1. Simplicity for humans to read and write
5. DATA SERIALIZATION FORMATS MOSTLYDATA SERIALIZATION FORMATS MOSTLY
FALL INTO TWO CATEGORIES:FALL INTO TWO CATEGORIES:
1. Simplicity for humans to read and write
2. Simplicity for machines to read and write
6. We’ll stick to those special formats that web systems
can understand, or be made to understand without
much effort, and that are particularly useful for human
readability:
XML, JSON, TOML, CSON, AND YAML.XML, JSON, TOML, CSON, AND YAML.
7. XMLXML
Originally, the XML language was amazingly flexible
and easy to write, but its drawback was that it was
verbose, difficult for humans to read, really difficult for
computers to read, and had a lot of syntax that wasn’t
entirely necessary to communicate information.
8. TODAY, IT’S ALMOST DEAD FOR DATATODAY, IT’S ALMOST DEAD FOR DATA
SERIALIZATION PURPOSES ON THE WEB.SERIALIZATION PURPOSES ON THE WEB.
9. Some XML greybeards beginning to scribble upon their
stone tablets as to why XML is ah-may-zing, so I’ll
provide a small addendum: XML can be easy to read
and write by systems and people. However, it is really
hard to create a system that can read it to
specification.
10. HERE’S A SIMPLE, BEAUTIFUL EXAMPLE OF XML:HERE’S A SIMPLE, BEAUTIFUL EXAMPLE OF XML:
11. Wonderful. Easy to read, reason about, write, and code
a system that can read and write.
BUT CONSIDER THIS EXAMPLE:BUT CONSIDER THIS EXAMPLE:
12. IMPOSSIBLE TO READ, UNDERSTAND, OR REASONIMPOSSIBLE TO READ, UNDERSTAND, OR REASON
ABOUT.ABOUT.
Writing code that can consume and understand this
would cost at least 36 heads of hair and 112 kilos of
coffee grounds.
13. So let’s let it live only in our memory alongside css
hacks, internet explorer 6, and vacuum tubes.
14. JSONJSON
It’s used just about everywhere nowadays. The format
is easy to write by both human and machine, fairly
easy to parse with strict rules in the specification, and
flexible—allowing deep nesting of data, all of the
primitive data types, and interpretation of collections
as either arrays or objects.
15. JSON SYNTAX IS STRAIGHTFORWARD.JSON SYNTAX IS STRAIGHTFORWARD.
Square brackets denote arrays, curly braces denote
records, and two values separated by semicolons
denote properties (or ‘keys’) on the le , and values on
the right. All keys must be wrapped in double quotes.
17. IT’S NICE AND CONCISE, AND HAS STRIPPED MUCHIT’S NICE AND CONCISE, AND HAS STRIPPED MUCH
OF THE EXTRA NONSENSE FROM XML TO CONVEY THEOF THE EXTRA NONSENSE FROM XML TO CONVEY THE
SAMESAME AMOUNT OF INFORMATION.AMOUNT OF INFORMATION.
18. TOMLTOML
(Tom’s Obvious, Minimal Language)
TOML allows for defining deeply-nested data
structures rather quickly and succinctly.
19. The syntax is a bit awkward when compared to JSON,
and is more akin to an INI file. It’s not a bad syntax, but
could take some getting used to:
20. A couple great features have been integrated into
TOML, such as multiline strings, auto-escaping of
reserved characters, datatypes such as dates, time,
integers, floats, scientific notation, and “table
expansion”.
21. The above expands to the following:
[a.b.c]1
d = 'Hello'2
e = 'World'3
"c": {
}
}
{1
"a": {2
"b": {3
4
"d": "Hello",5
"e": "World"6
}7
8
9
}10
22. There are few systems which use it or something very
similar for configuration, and that is its biggest con.
There simply aren’t very many languages or libraries
out there written to interpret TOML.
23. CSONCSON
(CoffeeScript-Object-Notation)
First off, there are two CSON specifications. One stands
for CoffeeScript Object Notation, the other stands for
Cursive Script Object Notation.
The latter isn’t used too o en, so we won’t be getting
into it. Let’s just focus on the CoffeeScript one.
24. CoffeeScript is a language that runs through a
compiler to generate JavaScript.
It makes writing JavaScript easier by removing a lot of
the extra syntax necessary in JavaScript. A big one that
CoffeeScript gets rid of is curly braces—no need for
them.
25. CSON IS JSON WITHOUT THE CURLYCSON IS JSON WITHOUT THE CURLY
BRACES.BRACES.
It instead relies on indentation to determine hierarchy
of your data. CSON is very easy to read and write and
usually requires fewer lines of code than JSON
because there are no brackets.
26. CSON ALSO OFFERS UP SOME EXTRA NICETIES THATCSON ALSO OFFERS UP SOME EXTRA NICETIES THAT
JSON DOESN’T HAVE TO OFFER.JSON DOESN’T HAVE TO OFFER.
27. CSON ALSO OFFERS UP SOME EXTRA NICETIES THATCSON ALSO OFFERS UP SOME EXTRA NICETIES THAT
JSON DOESN’T HAVE TO OFFER.JSON DOESN’T HAVE TO OFFER.
Multiline strings
28. CSON ALSO OFFERS UP SOME EXTRA NICETIES THATCSON ALSO OFFERS UP SOME EXTRA NICETIES THAT
JSON DOESN’T HAVE TO OFFER.JSON DOESN’T HAVE TO OFFER.
Multiline strings
you can enter comments by starting a line with a
hash
29. CSON ALSO OFFERS UP SOME EXTRA NICETIES THATCSON ALSO OFFERS UP SOME EXTRA NICETIES THAT
JSON DOESN’T HAVE TO OFFER.JSON DOESN’T HAVE TO OFFER.
Multiline strings
you can enter comments by starting a line with a
hash
no need for separating key-value pairs with commas
30. EXAMPLE OF CSON:EXAMPLE OF CSON:
title: 'JavaScript: The Good Parts'
description: 'Unearthing the Excellence in JavaScript'
]
books: [1
id: 'bk102'2
author: 'Crockford, Douglas'3
4
genre: 'Computer'5
price: 29.996
publish_date: '2008-05-01'7
8
9
31. HERE’S THE BIG ISSUE WITH CSON. IT’SHERE’S THE BIG ISSUE WITH CSON. IT’S
COFFEESCRIPT OBJECT NOTATION.COFFEESCRIPT OBJECT NOTATION.
Meaning CoffeeScript is what you use to
parse/tokenize/lex/transcompile or otherwise use
CSON.
If this format is adopted by other systems, it could be
pretty useful in the developer world.