For me, rather, this is
not a standoff , but the choice of a more suitable and convenient type of data exchange between the client and the server, for someone this choice may be completely different ...
Since on the client I often (90%) use JavaScript, JSON is my
de facto ! Who is he for the beast?
JavaScript Object Notation json.org - object notation (description of objects) in JavaScript. On the site you can read his full definition or, in extreme cases, on
ru.wikipedia.org/wiki/JSONWhy JSON?- A native description of objects for JavaScript, which is converted to an object by a single eval function. For more secure processing, you can use the special library json.org/json.js
- Support for all basic data types that can easily be parsed (converted) from any programming language
- Minimal semantic representation, which allows at times to reduce the size of the server response, and consequently, the load on it.
')
PHP conversion example
$data = array( 'a' => 'hello' , 'b' => 100, 'c' => array( 'd' => 'planet' , 'longstring' => 'oops' ) );
* This source code was highlighted with Source Code Highlighter .
in
XML (84 bytes):
< data >< a > hello </ a >< b > 100 </ b >< c >< d > planet </ d >< longstring > oops </ longstring ></ c ></ data >
* This source code was highlighted with Source Code Highlighter .
in
JSON (60 bytes):
{ "a" : "hello" , "b" :100, "c" :{ "d" : "planet" , "longstring" : "oops" }}
* This source code was highlighted with Source Code Highlighter .
From this it follows that in JSON we save
24 bytes of traffic, and this amounts to
28.57% of the XML traffic in this particular case.
Of course, in JSON there are no such things as XPath, XSLT, XQuery, XLink, XPointer. There are no attributes in JSON. And for Russian, it's better to use utf8 in JSON. But for javascript it is perfect, since json
itself is javascript.