viernes, 25 de octubre de 2013

Web: XML vs JSON

Tuve que hacer un documento en inglés sobre las características de XML y JSON hace algún tiempo, y me parece que quedó bastante bien, así que os lo dejo por aquí, cuando tenga algo de tiempo planeo "retraducirlo" al español pero por ahora os dejo el original.



Overview

In this document we show the differences and similarity of two of the most important formats to interchange information.

XML (eXtensible Markup Languaje) is a markup language derived from SGML (Standard Generalized Markup Language). It was developed by W3C (World Wide Web Consortium) looking for simplicity, generality and usability over the Internet. In the next code fragment we can see an example of how XML represents information.


 
  Bisbal
  Buleria
  10/05/2010
 

Example XML

JSON, an acronym of JavaScript Object Notation, created by Douglas Crockford is a light format to interchange data. The simplicity of JSON has made it really used, as an alternative to XML in AJAX. We show now the same information than in the previous code block but using JSON instead of XML.

{
    "albums": {
        "album": [
            {
                "artist": "art",
                "title": "GG",
                "date": "21/02/2010"
            }
        ]
    }
}

Example JSON

Discussion

Both are ways to represent information, but the way JSON uses is easier to understand at first sight than XML. Even with the use of squiggles, squares, colons and commas of JSON makes the writing of JSON files quicker than the XML files.

Extensibility

One of the differences is the extensibility, with XML (as its name shows) you can create new elements easily and represent arbitrary data structures, with JSON this is not possible, but is not exactly a weak point, because JSON does not search that, it is not a document markup language so it doesn’t need it.

Simplicity

Speaking about simplicity, JSON is simpler than XML because has a smaller grammar and the mapping of the XML basic tree to the types of the programming languages and databases could be difficult, because it was not the initial objective of XML. Sometimes the size of a JSON file could be greater than a XML file but its point is that represents better data structures and requires less codification and processing. Also has things in common, both are human readable and self-describing so any person can read a file and understand it in some way and the values has always a name (except arrays in JSON).

Data interchange

The eval() procedure of JavaScript allows a really easy way to process JSON data, but has some security problems. In general JSON needs much less specialized software than XML, or even does not need it at all, like JavaScript or Python, where the JSON notation is built into the language, in other cases you need third-party packages to support JSON, but there are a lot and they are rising each day. For XML the analyzer is a standard component, so it does not necessary create an specific analyzer for each XML version.


Interoperability

In terms of interoperability both of them offer good results making easier use the information inside the files to facilitate the communication between systems. JSON is used typically in works where the size of the data interchanges between client and server is highly important when the origin of the data is secure and where it is not important the absence of XSLT processing to manipulate the client data.

Openness

About openness JSON is more open than XML, because XML has behind it the World Wide Web Consortium, which makes do changes much more complicated and slow. In some way this is better because the W3C is a really big corporation which helps to XML keeps its presence in the world. Due to this background support there are a lot of use of XML and many developer tools to work with it, not only as an interchange format, also as an document format.

But despite of all these differences and similarities, it is frequent find JSON and XML in the same application, they are not always fighting each other to win. For example, if you have a client application using Google Maps data and also meteorology data in SOAP, these two elements make necessary use both formats (JSON and XML respectively).

Opinion

In my opinion, I think when you need to describe an information XML is clearer to read and easier to structure than if you start with JSON, and it is more difficult to make a mistake writing XML code than JSON because all the extra characters JSON uses. Despite the fact in some way JSON is simpler than XML, but for me I am more comfortable using XML. Besides in a really big hierarchical file will be more confusing in JSON than in XML (at least for me).

I think I feel better using XML than JSON because I am more used to see and write HTML (Hyper Text Markup Language) (remind HTML is based on SGML too) and I know how to manage it due to all the time I have been developing web applications. I have used JSON too but not as much as HTML, and usually only because I have been forced to use it due to the characteristics of the applications I was working.
But I recognize that JSON is less heavy to process because is simpler than XML and speaking of interchange of data could be a better option than XML.

Conclusion

To summarize both languages are really good and powerful and you need to know when you have to use XML or JSON, and know how to use them, because you never know when you can find out that the application you are developing has to connect with another that use other type of format different than you are using.

So if you need only transfer data you should use JSON but if you need transfer documents XML will suit it better.

Anyway XML is still more used than JSON but the latter is quickly growing.


Pues eso es todo el trabajo, iré añadiendo algunos más que tengo que me parecen interesantes!

Un saludo!

No hay comentarios:

Publicar un comentario

Ponte un nombre aunque sea falso, que Anó-nimo queda mu feo :(