views:

100

answers:

4

Possible Duplicate:
What are the pros and cons of XML and JSON?

I don't know of a web facing language that doesn't support both JSON and XML. So I'm sure this has nothing to do with serving different formats because of needs.

My guess is that people are still making new web services using XML because that's what they know, or the web service was built before JSON was well known. However, regardless of what I think...

Are there somethings that JSON can't do which is why people still use XML as the format for new things? I personally started with XML but when JSON came out I made the switch since:

  • JSON is easier to process (a lot less rules about syntax)
  • JSON is smaller (and bandwidth matters!)

Any answer that shows a XML fitting a API use-case better than JSON is good enough for me.

A: 

XML is better for data interchange between systems because it is very well understood and human readable (making interpreting easier for you).

Source.

Also see this question.

Matt Ball
Ah, readability can be a huge help when in the development stage of writing a library to read/post from a web service. Then again, if the web service is returning valid data why not just parse it and show the formated result? That would be much easier to read than raw XML/JSON. If no one has any better reason than this I'll accept this.
Xeoncross
Granted, I don't have much experience using XML, but that statement strikes me as wrong. I find JSON very readable and most XML I see is utterly unreadable. Of course, my JSON experience is relatively modern web APIs and my XML experience is mostly through parsing Word and Pages.app documents.
kubi
A: 

An article I read a while back indicated the following but I unfortunately cannot find the source nor been able to find anything that validated or refuted the claim.

It seems that both YAML and JSON are faster to encode for up to about 5000 elements, then XML takes over. It also looks like both YAML and JSON require twice as much memory as XML when decoding.

KayakJim
If the quotation is not sourced, and has no claim to validity, you may not want to bother
Frank Schwieterman
http://webignition.net/articles/xml-vs-yaml-vs-json-a-study-to-find-answers/ Google FTW? Although Bing gives the identical result. So, <favorite search engine> FTW?
JulianR
+1  A: 

JSON is "only" a format for data exchange. XML is more powerful because of it includes a data type description (DTD) as well.

But I think you are right: In most cases a simple data exchange format like JSON fits best.

Ah, yes, I was thinking in terms of data exchange only. I suppose XML can handle more abstract uses. So for the purpose of web services I guess JSON is good (it's all data exchange) - but for complex company systems XML is good.
Xeoncross
+1  A: 

Sometimes it is very important to have a rich validation of input data. For the purpose the usage of XML Schema (XSD), XPath or XSLT is very practical. There are of cause some approaches for JSON Schema but the technique has mostly draft label and in not a well-known and used standard like XSD.

So in some cases I use JSON (also JSON only without XML support) and in another cases I do use XML with XML Schema.

Oleg