What are the relative merits of CSV, JSON and XML for a REST API? What are the relative merits of CSV, JSON and XML for a REST API? xml xml

What are the relative merits of CSV, JSON and XML for a REST API?


Advantages:

  • 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(?)

Disadvantages:

  • 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 wouldn't even bother supporting CSV. The client can generate it from either XML or JSON if it's really needed.


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

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


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