XML and JSON: a comparison

XML is a descriptive markup language. What's more, XML is able to provide detailed descriptions of complex data structures. Many developers think that JSON is enough for them, but they're wrong. JSON is useful when you have to describe simple data structures, because JSON is not extensible. For such reason, JSON turns out to be perfect when the resource you're describing doesn't change much over time. But for dynamic structure, the extensibility of XML plays a major role. For example, JSON is excellent for a resource such as an RSS feed. This kind of resource has a predefined set of elements and attributes which is always the same on the entire web. On the contrary, JSON is inadequate when it comes to describe a complex framework or application.

Now a careful reader may say: "Doesn't Google Chrome use a JSON-like format to describe some of its internal features?". That's correct. But what kind of features? Browser preferences, which are very simple and predictable, because they usually involve a structure like this:

   "checksum": "",
   "roots": {
      "bookmark_bar": {
         "children": [ {
            "children": [ {
               "date_added": "",
               "id": "",
               "name": "",
               "type": "url",
               "url": ""

Not surprisingly, on Mac OS X Google Chrome uses a PLIST format, which is an XML-based format, to store more important and structured data:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" 
<plist version="1.0">
 <string>Google Chrome</string>
   <string>GIF image</string>

As you can see, when the complexity level of the resource to be described increases and, what's more, when flexibility and extensibility are a required feature, XML comes into play. So XML and JSON differ mainly from each other simply by this: extensibility and complexity.

This entry was posted in , by Gabriele Romanato. Bookmark the permalink.

3 thoughts on “XML and JSON: a comparison”

  1. This doesn't seem to exercise any special features from XML, though. It can be easily represented in JSON:

    { "CFBundleDevelopmentRegion":"en",
    "CFBundleDisplayName":"Google Chrome",
    [ { "CFBundletypeExtensions":
    [ "gif" ],
    "CFBundleTypeIconFile": "document.icns",
    [ "image/gif" ],
    "CFBundleTypeName": "GIF image",
    [ "GIFf" ],
    "CFBundleTypeRole": "Viewer"

    As usual for simple data like this, the JSON is just simpler and easier.

  2. What do you mean by extensible? How is JSON not extensible? You can easily add new fields in JSON objects.

    To quote http://www.json.org/xml.html:

    JSON is not extensible because it does not need to be. JSON is not a document markup language, so it is not necessary to define new tags or attributes to represent data in it.

Leave a Reply

Note: Only a member of this blog may post a comment.