I heard someone state that “JSON is the same as XML.” Are JSON and XML comparable? What are the major similarities and differences of each?
There are a few StackOverflow Q&As which touch on comparing JSON and XML [1] [2] [3] [4] [5] [6] [7], but none provide a good, single point of reference focused on their major similarities and differences.
What is JSON?
JSON (JavaScript Object Notation)
is a lightweight text-based open standard designed for human-readable data interchange.JSON is a text format that is completely language independent but uses conventions that are familiar to programmers.Borrowing a JSON sample from Wikipedia, a JSON representation of a person might look like:
What is XML?
XML (eXtensible Markup Language)
is a simple, very flexible text format derived from SGML. According to Wikipedia, XML isa set of rules for encoding documents in machine-readable form. [... It's goals] emphasize simplicity, generality, and usability over the Internet. It is a textual data format[...].Again borrowing a XML sample from Wikipedia, an XML representation of a person might look like:
Comparison
Based on these simple definitions, it’s understandable that one could conclude that JSON and XML are comparable. If your goal is to use one or the other for simple data interchange over the Internet, as exhibited by the simple examples above, that goal is surely attainable and JSON and XML are, indeed, mostly comparable.
However, as you dig deeper into the specifications of each you begin to realize they are completely different standards with similar goals; each with overlapping use cases where one is much better suited than the other and where they are equivalent solutions (where the choice is a matter of the specific use case).
Though it may be just a bit biased,
The Fat-Free Alternative to XMLfrom the JSON site lists some good points of comparison. There are also theXML vs JSON !!! Dont compare.andJSON Pros and Consblog entries with some bullet points for comparison.Similarities
Differences