JSON is the New XML for Data Transfer

Posted by Fernando Zamora July 11, 2012M

I was thinking about a meeting today regarding transferring data between two systems. The mention of XML came up. XML has been well accepted for data transfer. There are many advantages to using XML compared to say binary data or flat file data (such as fixed length records or CSV records). The advantages of XML over these other type records are many. However, there is also one big disadvantage with XML, data bloat. XML requires a open and close tag for every element. Many times the tags embedded in XML take up more space than the actual data content.

I am not sure where this new way of transferring data came from. It could’ve came from the sudden popularity of JavaScript in the last couple of years. Who knows. But now, JSON is the new XML. JavaScript Object Notation or JSON (pronounced Jason or J-SUN – both are acceptable pronunciations). JSON is lighter in weight than XML and is more human readable than XML. Take a look at the example below.

Here is XML

<myrecord >
       <firstname> John </firstName>
        <dob>03/24/1990 </dob>
        <department>Development </department>
       <disciplinaryactions & gt; 20 </disciplinaryactions>

Here is the same record in JSON

    "employee": {
        "firstname": "John",
        "lastname": "Doe",
        "dob": "03/24/1990",
        "department": "Development",
        "disciplinaryactions": 20

You can see that the byte count in that one record was reduced by at least one third of the total file size. One third can mean a lot when you start multiplying that times the number of records times the number of requests times the number of clients.

This paper explains some of these concepts better than I can.


Keep in mind that I am talking about data transfer. JSON cannot completely replace XML because XML has additional functionality like XSLT (Extensible Stylesheet Language Transformations) which can be used to transform the XML directly into a report (HTML, or prepare for input for another consumer). Currently there is no viable solution for this with JSON(that I know of). In most data transfer cases XML is not used with XSL so if you don’t need to transform it with XSL, JSON is a good substitute for XML.

Here are some additional examples:


3 Responses to JSON is the New XML for Data Transfer

  • Dan Elder
    July 16, 2012

    Hey Fernando, shouldnt the closing tag for lastname be </lastname>

    • Editor
      July 16, 2012

      Yes I have corrected it.

  • Robert Jones
    July 20, 2012

    The file size can be significant. I converted a certain flat file into XML and it went from 6.5MB to 38MB – 32MB of structure overhead.

    However, I’m impressed with .NET’s XML facilities, notably X-DOM and LINQ to XML; I can see all processing from file-read to database-insert done completely with the data in XML structure.

    Getting the best of both file size and data manipulation may be to use the .NET provided JSON parser to get the JSON into XML with minimal fuss.

    Using the Little-known Built-in .NET JSON Parser

Leave a Reply

Post Comment

Connect With Us

Recent Posts

A Guide for Learning Design Patterns

July 28th 2016 by Fernando Zamora If you’ve been writing code for more than a year, you might have h...

Read More

Using UML to Analyze Legacy Code

June 30th 2016 by Fernando Zamora For every programmer out there creating brand new code and working...

Read More

Python vs. Other Languages

April 29th 2016 by Fernando Zamora For the last two months or so my fellow McLane Advanced Technolog...

Read More

Naming Your Adapter When Implementing the Adapter Pattern

October 19th 2015 by Fernando Zamora At some point in your project you may need to use a third party...

Read More

10 Methods to Help You Debug Legacy Code

September 24th 2015 by Fernando Zamora A large majority of the work we do in our project is to fix r...

Read More