JSON vs XML


Both JSON and XML can be used to receive data from a web server. The following JSON and XML examples both define an employees object, with an array of 3 employees:

{
  "employees": [
    { "firstName": "John",  "lastName": "Doe"   },
    { "firstName": "Anna",  "lastName": "Smith" },
    { "firstName": "Peter", "lastName": "Jones" }
  ]
}

<employees>
  <employee> <firstName>John</firstName>  <lastName>Doe</lastName>   </employee>
  <employee> <firstName>Anna</firstName>  <lastName>Smith</lastName> </employee>
  <employee> <firstName>Peter</firstName> <lastName>Jones</lastName> </employee>
</employees>

JSON is like XML because JSON is unlike XML because The biggest difference is XML has to be parsed with an XML parser, and JSON can be parsed by a standard JavaScript function.

Why JSON Is Better Than XML
It is because For AJAX applications, JSON is faster and easier than XML because the following steps are taken if XML is used: and if JSON is used:

Demonstration
The following demonstration shows how the script of HTML and JavaScript is displayed on the Web.