📜 ⬆️ ⬇️

JSON vs. XML

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/JSON

Why JSON?

')
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.

Source: https://habr.com/ru/post/51657/


All Articles