Advantages of JSON
Typically, in an XML environment, the sender encodes the data to serialized, by using a DTD that the recipient can comprehend. This task involves a lot of additional padding around the data, regardless of which DTD in use. Thus the size of the XML documents is significantly larger than the actual data values to be sent. Then, the recipient obtains the XML data stream and decodes it for putting in the memory.
The other standard to compare is Yaml Ain’t Markup Language (YAML) that serializes complex data sets without a DTD and relies on a simpler parser than XML. Even such a parser consumes more time than JSON to output larger streams of serialized data.
Following are some more benefits of using JSON:
- JSON parses faster than XML and YAML.
- JSON is simpler to map to an object oriented system, as it is data-oriented.
- JSON easily differentiates between the string ‘2’ and the number ‘2’ as well as between a single item and a collection of size one (array).
- JSON is an ideal data exchange format, and not an ideal document exchange format as XML. Thus, it is not necessary for JSON to be extensible for exchanging documents by defining new tags for representing data.