JSON is faster because it is designed specifically for data interchange. JSON encoding is terse, which requires less bytes for transit. JSON parsers are less complex, which requires less processing time and memory overhead. XML is slower, because it is designed for a lot more than just data interchange.
JSON is a good choice if you want to transmit data from a client to a server. JSON data is readily processed by most programming languages. This means that you will not have to do any data parsing on either the client or the server side after data has been sent. XML is good if you need to separate data from HTML.
It is a text-based way of representing JavaScript object literals, arrays, and scalar data. JSON is relatively easy to read and write, while also easy for software to parse and generate. It is often used for serializing structured data and exchanging it over a network, typically between a server and web applications.
JSON is quicker to read and write. XML file takes time to read and write because the learning curve is higher. JSON can use arrays to represent the data. XML does not contain the concept of arrays.
Favor XML over JSON when any of these is true:
Favor JSON over XML when all of these are true:
I use JSON unless I'm required to use XML. It's simpler to understand, and (because it requires less configuration overhead) it's easier to program for reading and writing if the libraries are available in your context, and they're pretty ubiquitous now.
When Amazon first exposed their catalogs as a web service, they offered both JSON and XML. Something like 90% of the implementers chose JSON.
Considering your specific case where you're already doing javascript on the client side, I'd go with JSON for these reasons:
Since JSON is native to javascript
you'd have to write less code on the
client side - Just eval()
(or, better yet, JSON.parse()
) the JSON
string and get an object you can
use.
At the same time evaluating JSON on the client-side will be more efficient, and therefore faster.
JSON serialization produces shorter strings than XML. Using JSON will reduce the amount of data running across the wire and improve performance in that respect.
Here's some further reading: http://www.subbu.org/blog/2006/08/json-vs-xml
Some other things that I have run into in the XML vs JSON relm:
JSON is very good for
Which means it tends to like an array or nested array. However JSON is missing both
So if you were to combine two or more JSON services there could be potential namespace conflicts. That being said JSON can be used for about 90% of the same things XML can be used for when exchanging data in my experience.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With