tags:

views:

32

answers:

1
+2  Q: 

Ajax: Json vs XML

With the exception of needing an XML file, is there a benefit to using XML over JSON? JSON seems like an easier way to handle a return but I have very little experience using one or the other

+2  A: 

I recommend JSON over XML when doing Ajax. Why? Because a JavaScript engine can easily turn that JSON response into a JavaScript object... allowing you to access/manipulate that data very easily. You just have to use eval() or JSON.parse() or something similar (depending on the browser/javascript library).

JSON is valid JavaScript; so on the whole it meshes much better with Ajax/Javascript/Web than XML does.

JSON also tends to be a bit less verbose, especially in regards to arrays and key/value pairs... something you are likely to be encountering a lot with web services.

With XML people tend to create their own specialized XML vocabulary. So if anyone wanted to use your services, they'd also have to learn your XML vocab. JSON is much more universal in this regard.

Polaris878