There are many cases where it is useful to serialize data structures to text, such as persistence in the filesystem or transmission across the network. One of the most popular uses is to use ECMAScript to update a web page without reloading, using an asynchronous channel to a web server (AJAX). Other popular uses are for configuration files, data caches, simple networking protocols, and web-based data APIs.
The two most popular serialization formats are XML and JSON. Which do you think is preferable?
JSON has semantics for data types beyond text, such as numbers, lists, and associative maps. This allows data structures without complex objects to be serialized with very little fuss. Even moderately complex objects may be serialized if they can be reduced to basic data types.
One way to do it. In XML, it is a choice of the programmer on whether to use attributes or child elements to store associated data. Each has its own advantages and disadvantages (generality v. simplicity). The child element method provides both associative mapping and list behavior.
JSON separates these into different syntaxes, so that mappings use {} and lists use .
After parsing, a JSON data set can be accessed directly within a browser through standard syntax. XML requires use of the DOM for traversal, which is complex enough to have tutorials [w3schools.com].
XML has standard facilities for metadata such as the text encoding and language, and can be serialized in any encoding. JSON relies on encoding autodetection, and therefore may only be serialized to one of the UTF-* encodings.