There has been much debate on using XML or JSON with your AJAX, but in my mind, the debate is pointless. Both are nice, one is quicker, one is slower. However, when it comes to development pick what you know best and what you can implement/maintain easiest.
If you do this, you are guaranteed the following:
- It is easy to maintain and understand the code you wrote months later
- Chances are your application will not be the quickest in response
- You will make use of techniques you fully understand than trying to adapt ones that you are unfamiliar with and may implement wrong
So how does JSON differ from returning XML in your AJAX requests? Lets first look at the advantages of XML.
- Standardized and easily serialized into via .NET
- The XML is easy to read all within itself
- You can make use of XSLT, DTDs, etc
How about disadvantages of XML?
- It is slow in comparison to JSON
- It can be clumsy when not designed properly
Now for the advantages of JSON:
- It is faster than XML to parse in JavaScript
- There are addin’s you can install in .NET or a library in PHP to serialize a JSON string from an object
- It is hard to make this clumsy as it is based on the Object Design
And the disadvantages of JSON:
- It is harder to read the serialized output
- You can’t use XSLT, DTDs, or something of the sort to validate or style the request
As for myself, I am a JSON person. I didn’t used to be though. My original AJAX applications were focused around XML primarily because I could make use of an XSLT and I always validated against a schema. However, JSON has won me over due to speed. JSON’s speed is just ridiculously fast and it showed when I converted a major application over to it. I saved nearly a third of the time it took to do a fairly simple task.
However, pick the poison that you understand most, otherwise, it could have detrimental affects.
0 comments ↓
There are no comments yet...Kick things off by filling out the form below.
Leave a Comment