Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

JSON vs XML

JSON vs XML

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

JSON and XML differ in notation, as shown below:

JSON example

{

"

sites

"

:

[

{

"

name

"

:

"

Runoob Tutorial

"

,

"

url

"

:

"

www.runoob.com

"

}

,

{

"

name

"

:

"

google

"

,

"

url

"

:

"

www.google.com

"

}

,

{

"

name

"

:

"

Weibo

"

,

"

url

"

:

"

www.weibo.com

"

}

]

}

XML example

<

sites

<

site

<

name

Runoob Tutorial

name

<

url

www.runoob.com

url

site

<

site

<

name

google

name

<

url

www.google.com

url

site

<

site

<

name

Weibo

name

<

url

www.weibo.com

url

site

sites

Similarities between JSON and XML:

Differences between JSON and XML:

The biggest difference isXML needs an XML parser to be parsed, while JSON can be parsed using standard JavaScript functions.

  • JSON.parse()Converts a JSON string into a JavaScript object.
  • JSON.stringify()Converts a JavaScript value into a JSON string.

  • Why is JSON better than XML?

    XML is harder to parse than JSON.

    JSON can be parsed directly using existing JavaScript objects.

    For AJAX applications, JSON loads faster and is simpler than XML data:

    Using XML

    Using JSON


    Related Articles