[ACCEPTED]-What are the relative merits of CSV, JSON and XML for a REST API?-csv

Accepted answer
Score: 24


  • XML - Lots of libraries, Devs are familiar with it, XSLT, Can be easiily Validated by both client and server (XSD, DTD), Hierarchical Data
  • JSON - easily interpreted on client side, compact notation, Hierarchical Data
  • CSV - Opens in Excel(?)


  • XML - Bloated, harder to interpret in JavaScript than JSON
  • JSON - If used improperly can pose a security hole (don't use eval), Not all languages have libraries to interpret it.
  • CSV - Does not support hierarchical data, you'd be the only one doing it, it's actually much harder than most devs think to parse valid csv files (CSV values can contain new lines as long as they are between quotes, etc).

Given the above, I 3 wouldn't even bother supporting CSV. The 2 client can generate it from either XML or 1 JSON if it's really needed.

Score: 19

CSV is right out. JSON is a more compact 9 object notation than XML, so if you're looking 8 for high volumes it has the advantage. XML 7 has wider market penetration (I love that 6 phrase) and is supported by all programming 5 languages and their core frameworks. JSON 4 is getting there (if not already there).

Personally, I 3 like the brackets. I would bet more devs 2 are comfortable with working with xml data 1 than with json.

Score: 3

XML can be a bit heavyweight at times. JSON 3 is quite nice, though, has good language 2 support, and JSON data can be translated 1 directly to native objects on many playforms.

Score: 2

CSV has so many problems as a complex data 9 model that I wouldn't use it. XML is very 8 flexible and easy to program with - clients 7 will have no problem coding XML generators 6 and parsers, you can even provide sample 5 parsers using SAX.

Have you checked out Google's 4 network data format? It's called Protocol 3 Buffers. Don't know if it is useful for 2 a REST service however as it skips that 1 whole HTTP layer too.

Score: 1

I don't have any experience with JSON, CSV 9 works up to a point when your data is very 8 tabular and evenly structured. XML can become 7 unwieldy very quickly, especially if you 6 don't have a tool that creates the bindings 5 to your objects automatically.

I have not 4 tried this either but Google's Protocol Buffers look really good, simple 3 format, creates automatic bindings to C++, Java 2 and Python and implements serialisation 1 and deserialisation of the created objects.

Score: 1

Asides from what Allain Lalonde already said, one additional advantage of 7 CSV is that it tends to be more compact 6 than XML or even JSON. So, if your data 5 is strictly tabular, with a completely flat hyerarchy, CSV 4 may be a correct choice. Additonal disadvantages 3 of CSV is that it may use different delimiters 2 and decimal separators, depeding on which 1 tool (and even country!) generated it.

More Related questions