Data efficiency - return in JSON or XML?

I have a fairly large dataset returned via AJAX from a page. This can be up to 0-20 thousand records at a time, each of which contains about 10 data units. Now, at the moment, the data is returned in structured XML, and javascript is working with it (for writing I am using jQuery at the moment).

When XML returns, jQuery goes through all the nodes named address (using the .find() function). Then it sorts the data and can take any amount of time. However, it seems that the code is not as efficient as it may be, and I have no experience with fairly large data. I believe that the advantages of XML are that we can easily integrate it into other things, such as web services, etc., but the efficiency will be much better, since we do not want to leave the user hanging. So I'm sure other people may have asked this before, but which is more efficient - XML ​​or JSON?

Also, which one is more useful or are they the same?

Sorry if this is a lame question, this is one of the first cases when I used JSON!

+4
performance json xml
source share
2 answers

JSON is a designation for serializing objects. This is his focus and purpose. XML is intended to define markup languages, but I don’t like it if people clog this fact as if it cannot be used for data. I find XML very suitable for representing many data structures. However, XML is rather universal, and this leads to some overhead in terms of specification, notation, and tool size.

First of all, find out what you need. Is it necessary to transfer data in a more general sense or is it enough to bypass objects? Will you require things like namespaces? Choose a technology that does what you need, but nothing more. But remember the future expansion.

Secondly, consider the tools. XML has great support in almost any language. There are methods for in-memory representation (DOM), object binding (JAXB in Java), parsing (SAX) ... Does JSON support this support in your target environment? JSON, on the other hand, is extremely user-friendly in conjunction with JavaScript.

I believe that you can do what you need, regardless of the choice of technology, and in each of the options there is a place for optimization. But there is one last thought: maybe you do not need to choose. Sometimes it is very simple to enable serialization of data as JSON or XML. As a Java programmer, this is the only example I can come up with, but in JAX-WS there are methods for retrieving data from web services like XML, JSON, or perhaps even other formats with minimal code adaptation.

+7
source share

My personal opinion:

I do not really like XML. But it depends on the depth of the transmitted objects. If you don't need a bunch of attributes and tags to represent your xml data, this is definitely not the best choice. ( Examples and more) . When I can freely define my own data structure and hierarchy, JSON is much faster. In addition, the syntax is not as heavy as xml, so you can save some bits or even bytes for each transmission.

For me there is only one reason to use XML in modern applications: usability! When you apply for open standards (for example, using REST with ATOM Frontend ). You quickly see the benefits in collaboration with other developers.

In the end, it's up to you how your data will look, and then choose the best presentation.

+2
source share

All Articles