Java Reference
In-Depth Information
The serialization format that web developers overwhelmingly embrace is called JavaScript Object
Notation, or JSON (pronounced like the name: Jason). It is a subset of the JavaScript language;
as such, it's easy to read, it's concise, and most importantly, it's easy to serialize to and deserialize
from.
But the web hasn't always used JSON for serializing JavaScript objects. So before we look at the
JSON format, let's look at what web developers used to use.
xml
There was a time when the web development community embraced XML for just about everything.
Web services used it to communicate with one another and other computers, and JavaScript
developers used it to communicate with the web application's server.
XML is a human‐readable language thanks to its declarative syntax. It's not necessary for humans
to read XML data, but being able to read and decipher the XML can be useful. Consider the
following XML document as an example:
<person>
<firstName>John</firstName>
<lastName>Doe</lastName>
<age>30</age>
</person>
Despite being a simple document, you know that this XML represents an individual person named
John Doe who is 30 years old. You could catch and fix errors that may occur in your application as
it generates the preceding XML‐formatted data.
XML is also machine‐readable, and it was a known commodity when developers started using
it. Every modern programming language had the tools and capabilities for reading, parsing, and
creating XML‐formatted data, and so using XML to communicate between computer systems and
applications seemed like a good idea.
But XML has its drawbacks. For one, XML's declarative syntax adds a lot of extra cruft to the data.
Look again at the XML describing a person named John Doe:
<person>
<firstName>John</firstName>
<lastName>Doe</lastName>
<age>30</age>
</person>
This simple XML is 101 bytes. That's not large by today's standards, but remember that this is just
an example. This is information that a computer would send over the Internet to another computer.
First, the opening and closing <person> tags surround the actual data. Of course, the outer
<person/> element exists for organizational purposes, but it is 17 bytes—16 percent of the entire
payload. Other formats will still have some way to organize the document's real information (the
first and last name), but they would be smaller in size.
 
Search WWH ::




Custom Search