JSON an XML Alternative

I recently came a cross a blog talking about JSON, a straight forward alternative to XML. I’ve always disliked XML, and so has pretty much everyone I’ve ever known who’s had to muck with it. It’s not terrible, just clunky, and seems so much less efficient than the one-off csv type files most of the unixy folks I associate use. JSON tries to combine the two, but has easy-to-read, simple, lightweight, and yet is standard and portable. How cool is that?

From www.json.org’s description:

Extensible Markup Language (XML) is a text format derived from Standard Generalized Markup Language (SGML). Compared to SGML, XML is simple. HyperText Markup Language (HTML), by comparison, is even simpler. Even so, a good reference book on HTML is an inch thick. This is because the formatting and structuring of documents is a complicated business.

Most of the excitement around XML is around a new role as an interchangeable data serialization format. XML provides two enormous advantages as a data representation language:

  1. It is text-based.
  2. It is position-independent.

These together encouraged a higher level of application-independence than other data-interchange formats. The fact that XML was already a W3C standard meant that there wasn’t much left to fight about (or so it seemed).

Unfortunately, XML is not well suited to data-interchange, much as a wrench is not well-suited to driving nails. It carries a lot of baggage, and it doesn’t match the data model of most programming languages. When most programmers saw XML for the first time, they were shocked at how ugly and inefficient it was. It turns out that that first reaction was the correct one. There is another text notation that has all of the advantages of XML, but is much better suited to data-interchange. That notation is JavaScript Object Notation (JSON).

The most informed opinions on XML (see for example xmlsuck.org) suggest that XML has big problems as a data-interchange format, but the disadvantages are compensated for by the benefits of interoperability and openness.

JSON promises the same benefits of interoperability and openness, but without the disadvantages.

Let’s compare XML and JSON on the attributes that the XML community considers important.

Here’s a neat example of some jason formatted data:

{
     "firstName": "John",
     "lastName": "Smith",
     "address": {
         "streetAddress": "21 2nd Street",
         "city": "New York",
         "state": "NY",
         "postalCode": 10021
     },
     "phoneNumbers": [
         "212 555-1234",
         "646 555-4567"
     ]
 }
This entry was posted in Uncategorized. Bookmark the permalink.

1 Response to JSON an XML Alternative

  1. Yes… but…

    When it come to sending a long list of data objects all of the same type, CSV is stubbonly popular.

    http://myediblog.blogspot.com/2008/07/alternative-edi-formats-part-i-csv-json.html

Leave a Reply