Loading Please Wait...

Logo Lynxsia IT Solutions

JavaScript JSON Vs XML

JS JSON vs XML

Both JSON and XML can be used to receive data from a web server.

XML Data

The following XML examples defines an employees object, with an array of 3 employees:

					 
        
          <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 Data

The following JSON examples defines the same employees object:

					 
        
          {"employees":[
            { "firstName":"John", "lastName":"Doe" },
            { "firstName":"Anna", "lastName":"Smith" },
            { "firstName":"Peter", "lastName":"Jones" }
          ]}
        
      
JSON vs XML - Similarity

JSON is Like XML Because:

  • Both JSON and XML are "self describing" (human readable)
  • Both JSON and XML are hierarchical (values within values)
  • Both JSON and XML can be parsed and used by lots of programming languages
  • Both JSON and XML can be fetched with an XMLHttpRequest
JSON vs XML - Difference

JSON is Unlike XML Because:

  • XML has to be parsed with an XML parser. JSON can be parsed by a standard JavaScript function.
  • JSON doesn't use end tag
  • JSON is shorter
  • JSON is quicker to read and write
  • JSON can use arrays
Why JSON is Better Than XML

XML is much more difficult to parse than JSON. JSON is parsed into a ready-to-use JavaScript object.

For AJAX applications, JSON is faster and easier than XML.

Using XML:

  • Fetch an XML document
  • Use the XML DOM to loop through the document
  • Extract values and store in variables

Using XML:

  • Fetch a JSON string
  • JSON.Parse the JSON string

How you feel about this blog:

Share this blog on:

Report Us

If you find any error in the turtorials, or want to share your suggestion/feedback, feel free to send us email at: info@lynxsia.com

Contact Us
Ads
Logo
Lynxsia IT Solutions

We are concern with various development process like website design & development, E-commerce development, Software development, Application development, SMS & Bulk SMS Provider, PWA Development, and many more..

Kotwali Road, Chhiptehri, Banda, 210001, UP, India

Copyright © 2022, Lynxsia IT Solutions, All rights reserved