JSON or XML as hypermedia

For starters, I’ll propose that web services need to offer up multiple representations for a resource be it XHTML, RDF, Atom, XML or JSON, simply because you’ll run into someone who just lives and dies by a certain format.

Having said the above and now being at the point where I need to make a decision as to what format to use for my web services and being that my clients are generally non-browser (I rarely see REST discussed outside the context of browser front-ends, some additional posts on this would be great), XHTML is really not that appealing (even though it could work). Atom doesn’t seem to be a natural fit. This leaves me with deciding between XML or JSON.

I’ve used XML (and XSD) extensively in the past, so I really felt obliged to use this a my primary representation format. However, I began to objectively look at how I’ve used XML in the past and apart for validating using XSD, I can’t really say that I’ve used the document processing features and libraries (XPATH, XSLT etc) extensively i.e. I rarely treat my XML documents as “documents”. In fact, I use XML primarily for pure data transfer.

How do I know this? My code almost always, takes the incoming XML document and serializes it to an object that I can work with, finishes the business process, serializes the result of the process as XML and sends it back to the client. XML has been my ultimate data transfer format – and it has worked pretty well. However, JSON can work just as well (if not better) in such situations and ends up being closer to my problem domain.

I am not aware of a formalized way of specifying hypermedia (links) in JSON. If someone is aware of one, please share. But what I’ve chosen to do is mimic what you find in Atom with “link” metadata element.

I choose JSON (today).


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s