CSV vs XML vs JSON – Which is the Best Response Data Format?

October 19, 2018

Sand Pile, Port Colborne

Whether you are building a thin client (web application) or thick client (client-server application) at some point you are probably making requests to a web server and need a good data format for responses. As of today, there are three major data formats being used to transmit data from a web server to a client: CSV, XML, and JSON. In order to develop an application with a solid architecture, it’s 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 for each, and discover which situations work best with each format.

CSV

CSV stands for “comma separated values”. As the name implies, this data format is basically a list of elements separated by commas. Let’s say that your response 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. Generally speaking, CSV formats are about half the size of XML and JSON formats. This is the major advantage of CSV because it can help reduce 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. As a result, if the data structure changes, there is an associated overhead of having to change or even redesign your parsers. Furthermore, since the program creating the CSV and the program parsing the CSV 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 receiving program to crash. Otherwise, an outage is required to update both programs individually to prevent incompatibility issues.

Finally, CSV does not really support data hierarchies. What if you wanted to send back attributes for each person in each family? You would then have to design a complex parser that knows which parts of the CSV are referring to elements of a family, and which parts are referring to elements of each person. One way to solve this problem is to use another delimiter like “;” to separate each person’s attribute:

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

The problem with creating customized formats, however, is that you incur an overhead of maintaining an even 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 looks like this:

<person> <name><br /> Eric<br /> </name><br /> <age><br /> 26<br /> </age> </person> <person> <name><br /> Andrea<br /> </name><br /> <age><br /> 26<br /> </age> </person> <person> <name><br /> Kusco<br /> </name><br /> <age><br /> 8<br /> </age> </person>

Pros – This data format fully supports hierarchical data structures and is very appropriate when receiving complex data as a response. It is also very human readable. Most browsers have built in XML readers that allow you to inspect XML files. Since XML was the first standard hierarchical data format, most APIs have built in functionality to automatically convert XML data streams into native data structures like objects.

Cons – This data format is about three times as large as CSV. This is because each data element has an associated open and close parameter tag.

JSON

JSON stands for (Javascript Object Notation). It was invented in 2001 and became popularized by Yahoo and Google in 2005 and 2006. It was created as an alternative to XML. Like XML, however, it represents hierarchical data with the use of commas, curly braces and brackets. An example of JSON looks like this:

{“name”:”Eric”,”age”:”26″},

{“name”:”Andrea”,”age”:”26″},

{“name”:”Kusco”,”age”:”8″}

Pros – This data format supports hierarchical data while being smaller in size than XML. As its name implies, it was also created to more easily parse data into native Javascript objects, making it very useful for web applications. JSON is the best of both worlds with respect to CSV and XML. It’s simple and compact like CSV, but supports hierarchical data like XML. Unlike XML, JSON formats are only about twice as large as CSV formats.

Cons – This data format has a little bit less support than XML. Since JSON is relatively newer than XML, fewer APIs exist to automatically convert JSON to native data structures. However, this is rapidly changing because newer APIs and plugins are supporting both XML and JSON.

Conclusion

As a general rule of thumb, JSON is the best data exchange format to date. It’s light weight, compact, and versatile. CSV should only be used if you are sending huge amounts of data and if bandwidth is an issue. Today, XML should not be used as a data exchange format because it’s better suited for document markups.

29 Comments

  • Meh Rooz October 19, 2018 at 1:19 am

    I have lost my phone and i have signed on it also..Now I bought new fone can I get my secure folder data back

  • Pentafi Lover October 19, 2018 at 1:19 am

    I accidentally deleted my project like wtf why do I do that?

  • Inam-UL-Haq Lodhi October 19, 2018 at 1:19 am

    Thanks My friend Your videos it's so good Thanks

  • Lauren Stankiewicz October 19, 2018 at 1:19 am

    Does this work if photos were not synced?

  • Saju October 19, 2018 at 1:19 am

    Does this recover images inside your Private Folder on an S7 ?

  • Qasim Shah October 19, 2018 at 1:19 am

    Can i recover private mode picture after factory reset ??

  • Master AliefKhan October 19, 2018 at 1:19 am

    is this a virus?

  • Jaymie loves레드벨벳 October 19, 2018 at 1:19 am

    Excuse me. I think I accidentally deleted the files by clicking the cached data and deleting all the stuffs in it. Can I still recover it tho?

  • Peter Sanchez October 19, 2018 at 1:19 am

    does it work if I have a broken screen??

  • Mulah G October 19, 2018 at 1:19 am

    If you lost your photo albums on a Samsung Galaxy J3, does this work and do you have to do it immediately or at anytime. Or will they be fully gone if over a month.

  • T-O-E October 19, 2018 at 1:19 am

    my samsung galaxy s6 is stuck in recovery mode, it's crashed & i cant restart it. help me please before my wife murders me, all of our holiday photos are on there 🙁

  • Melisa Mena October 19, 2018 at 1:19 am

    How can I get deleted memos from Samsung galaxy S5 neo

  • Ryan Deaton October 19, 2018 at 1:19 am

    If I factory reset my phone without saving anything to the cloud can I still get my old files back?

  • asfiyah 001 October 19, 2018 at 1:19 am

    Does this still work on Samsung Galaxy S3? And does it also work after factory backup reset?

  • ItsSuperJeromeTV October 19, 2018 at 1:19 am

    Is it working on Galaxy J2 Prime? I accidentally deleted my videos a while ago.

  • Garret Botha October 19, 2018 at 1:19 am

    lol if you make this video you must be sure that you never downloaded porn or something.otherwise everyone will see it😂

  • Asma Rezai October 19, 2018 at 1:19 am

    How long does the analyzing take? I've downloaded the programme and it's been on 90% on the analyzing part for over an hour now. what do I do?

  • Eduardo Gomes October 19, 2018 at 1:19 am

    don't work on galaxy s7 edge?

  • mrcori October 19, 2018 at 1:19 am

    They did a factory reset on my phone thinking there was a problem when all it was was a bad battery. I lost everything. I started adding new photos before finding out about possible data recovery. My questions are is it safe to the phone to try this? And did my old data get overwritten by me adding new photos? Thank you.

  • shree vinay vidhya pratishthan October 19, 2018 at 1:19 am

    working it without root ????

  • josh r October 19, 2018 at 1:19 am

    my device won't root. Any reasons why?

  • Jennifer Irving-Chandler October 19, 2018 at 1:19 am

    do i need to root my device?

  • sothiegtv 9 October 19, 2018 at 1:19 am

    and I can't get it back

  • Elena Dim October 19, 2018 at 1:19 am

    i have samsung galaxy tab 3 lite and i deleted a file that had all my art, can i do something? couse i really want them all

  • Fazal Mfb October 19, 2018 at 1:19 am

    samsung A8

  • Kookie Crumbaliz October 19, 2018 at 1:19 am

    What if I deleted everything thing cuz of reset will it get it back?????

  • Khae Khae October 19, 2018 at 1:19 am

    I accidentally deleted allllll my music, can I get it back?

  • eNiiQx- SuJiNeRR- October 19, 2018 at 1:19 am

    i just foromat my phone and every thing is gone can i get them back ?

  • Rami Musmar October 19, 2018 at 1:19 am

    Do I need to root my phone?
    how to root it?

Leave a Reply

Your email address will not be published. Required fields are marked *