Json parsing vs xml parsing?
json, xml
Solution
Json...
has a smaller overhead comparred to XML - XML's closing tags increase boilerplate code size by a factor of about 2. It's also more human-readable - consider
{
"key": "value",
"other key": 3.1415926535897932,
"arr": [
1,
2,
3
]
}
versus
<?xml version="1.0"?>
<!-- not to mention the DTD declaration -->
<myXmlFormat>
<key>value</key>
<otherKey>3.1415926535897932</otherKey>
<arr>
<number>1</number>
<number>2</number>
<number>3</number>
</arr>
</myXmlFormat>
Is easier and quicker to parse (as it's more lightweight) - there are a lot of JSON parsers which are themselves smaller and quicker than their XML parser counterparts in the same programming language (consider libxml2 versus js0n).
JSON's data types also have a 1:1 mapping to data types traditionally considered "primitive" - such as strings, intergal and real numbers, arrays ans key-value tables. Furthermore, these primitive data types are easy to use with Foundation aa they're built into it - the above JSON can effortlessly parsed to an NSDictionary containing "key", "other key" and "arr" as keys, which correspond to the string "value", pi as an NSNumber and an NSArray, respoectively. Meanwhile XML has to be thought of additionally - maybe you have to even create custom classes to represent your own data structure described in the XML.
Specifically for the iOS platform: Cocoa's native XML parser, NSXMLParser is more than counterintuitive to use. The Foundation framework on iOS doesn't include the NSXMLNode class from Foundation on Mac OS X, and this forces developers to write their own spaghetto code to wrap all the XML to some structured data... well... structure instead of being able to use the included ones.
Problem
What are the advantage and disadvantage of json parsing? Why developers prefer to use json over xml parsing?