CSV vs JSON vs. XML - which is the best format for response data?

8:02 PM
CSV vs JSON vs. XML - which is the best format for response data? -

If you are building a thin client (web application) or at some point thick client (client-server), you are probably making requests to a Web server, and they need a good size data for the answers. To date, there are three main data formats used to transmit data from a Web server to a client: CSV, XML, and JSON. In order to develop an application with a robust architecture, it is a good idea to understand the differences between each format and know when to use them. The purpose of this post is to define each data format, lay out the pros and cons of each, and find out which situations work best with each format.

CSV

CSV stands for "comma separated values". As the name suggests, this data format is basically a list of items separated by commas. Let's say that the answer is sending back a list of people in a particular family. The format would look like this:

Eric, Andrea, Kusco

Pros - This format is the most compact of all three formats. In general, CSV formats are about half the size of XML and JSON formats. This is the main advantage of CSV, because it can help reduce the bandwidth

Cons - This format is the least versatile of all three formats. This is because a homemade parser is required to convert the CSV data into a native data structure. Therefore, if the data structure changes, there is an associated overhead of having to change or even redesign your parsers. Moreover, since the creation program CSV and CSV parser reside on different machines (remember that we are passing data from one machine to another), then both programs must be updated simultaneously to prevent the program of crash reception. Otherwise, the interruption is required to update both programs individually to avoid incompatibility problems.

Finally, CSV actually does not support data hierarchies. What if you wanted to return the attributes for each person in every family? You would then need to design a complex parser that knows which parts of the CSV refer to elements of a family, and which parts refer to elements of each person. One way to solve this problem is to use another delimiter such as ";" to separate the attribute of each person

Eric; male; 26, Andrea; female; 26, Kusco; male; 8

The problem with the creation of custom sizes, however, is that it incurs an overhead of maintaining a more complex parser.

XML

XML stands for "Extensible Markup Language". XML was designed in 1996 and officially became a W3C standard in 1998. It 'was created to better represent data formats with a hierarchical structure. The format is similar to the following:

<Person> <name> Eric <!-- name--> <age> 26 <!-- age--> <!-- person--> <person> <name> Andrea <!-- name--> <age> 26 <!-- age--> <!-- person--> <person> < name> Kusco <!-- name--> <age> 8 <!-- age--> <!-- person-->

Pros - This data format fully supports hierarchical data structures and it is very appropriate when you receive complex data as a response. It is also very readable. Most browsers have built in XML readers that allow you to inspect the XML file. Since XML was the first of the series of hierarchical data format, most APIs have built in function to automatically convert the XML data flows in structures of native data as objects.

Cons - This data format is about three times larger than CSV. This is because each data element has an opening tag and closing associated parameter.

JSON

stands for JSON (JavaScript Object Notation). E 'was invented in 01 and became popular as Yahoo and Google in 05 and 06. It' was created as an alternative to XML. XML, however, is hierarchical data with the use of commas, braces and brackets. An example of JSON is similar to the following:

{ "name": "Eric", "age": "26"},
{ "name": "Andrea", "age": "26"},
{ "name": "Kusco", "aged", "8"}

pro - This format data supports hierarchical data while being smaller in size than XML. As the name suggests, it was also created to analyze more easily the data in native JavaScript objects, making it very useful for web applications. JSON is the best of both worlds with respect to CSV and XML. It 'simple and compact like CSV, but supports hierarchical data as XML. A difference of XML, JSON formats are only about twice as large as CSV.

Cons - This data format has a little 'less XML support. Since JSON is relatively recent than XML, fewer APIs exist to automatically convert JSON to native data structures. However, this is changing rapidly, because the API and the latest plugins are supporting both XML and JSON.

Conclusions

As a general rule, JSON is the best format for data exchange to date. It is lightweight, compact and versatile. CSV to be used only if you are sending huge amounts of data and if the bandwidth is an issue. Today, XML should not be used as a format for exchange of data, because it is more suitable for markup documents.

Previous
Next Post »
0 Komentar