views:

443

answers:

4

Hi all,

Just a quick question (it's marked as a community wiki)

From experiences, have you found it easier to evaluate your ajax responses using XML or JSON when using ExtJS? Which format is ExtJs better for handling?

I'm torn between them.

Thanks!

+6  A: 

According to the ExtJS team, JSON is easier and faster to use.

In my former job, we tried both and definitely had better performance with JSON.

Robusto
"Also name JSON (JavaScript Object Notation) suggests that it has been designed with javascript in mind for intersystem communication."Sums it up very nicely. thank you for the link.But, do you not think for some data sets xml is better? i.e. i prefer returning xml for such things such as node stasues on a cluster system. Viewing the response is always easier to read and evaluate, although harder to manipulate in JS.
Jamie
If you're using something like Firebug or Chrome/Safari's Web Inspector, you can example JSON responses just as if they were an object. I'd recommend doing that or using http://chris.photobooks.com/json/default.htm to examine your JSON.
S Pangborn
+2  A: 

JSON, since javascript can handle this natively you don't have to use any extra libs etc for parsing it.

Justin
Most browsers can handle xpath natively aswell and in that case, doesn't need to eval the output as you need to with JSON.
jishi
@jishi: This is true, but JSON is a native object, and most JSON parsers are doing a lot more than just `eval()` as just using `eval()` is a security risk. JSON is a lot less bandwidth intensive, in a lot of situations, as well. http://stackoverflow.com/questions/974301/performance-considerations-of-json-vs-xml
S Pangborn
Using xpath is not the same as converting the data structure directly into a native JS object. To do that you'd still have to parse the XML.
bmoeskau
@S Pangborn: JSON wouldn't be a native object since it's only a string-representation of an object. @bmoeskau: I know that, and you make the assumption that one would want to convert the data into a native JS-object, that isn't always the case. For instance, if you want to iterate through the data and build DOM-elements of it, then the conversion between string -> js object -> DOM-objects can be a huge overhead. not to mention, if you just want a single value from a large XML.
jishi
@jishi -- if you are doing native JS programming, maybe. As the OP is using Ext, I see no reason why using xpath would make since since anything like that could be done more easily via the Ext API. Frankly, I haven't seen a real need for xpath + JS outside of doing XML "data islands" circa 2003.
bmoeskau
+1  A: 

JSON is definitely the way to go if you can produce it efficiently on the server-side (which usually isn't a problem for most languages).

SBUJOLD
A: 

If you are dealing with big datasets and need to find data within that set quick and easy, XML would probably be faster because it would parse it natively, and using native xpath-support it would probably find your data blazing fast.

Using JSON in those cases would require an eval on the data, and most json-parsers also validates a lot of the code for security reasons etc meaning that it wont be exclusively "native" code that processes it.

That will make a huge impact on the total processing time which would be a lot of overhead if you would only use a small sample in the data.

Both techniques has pros and cons, so it's more dependent on the actual case it will be used in.

jishi