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

JSON Introduction

JSON - Introduction


Online example

Through our editor, you can edit JavaScript code online and then view the result by clicking a button:

JSON example

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>

Runoob Tutorial(runoob.com)

title

head

<

body

<

h2

JavaScript creates a JSON object

h2

<

p

Site name:

<span id="jname" span>
<br/>

Site URL:

<span id="jurl" span>
<br/>

Site slogan:

<span id="jslogan" span>
<br/>p>
<script var JSONObject={"name">

:

"

Runoob Tutorial

"

,

"

url

"

:

"

www.runoob.com

"

,

"

slogan

"

:

"

What you learn is not only technology, but also dreams!

"

}

;

document

.

getElementById

(

"

jname

"

)

.

innerHTML

=

JSONObject

.

name

document

.

getElementById

(

"

jurl

"

)

.

innerHTML

=

JSONObject

.

url

document

.

getElementById

(

"

jslogan

"

)

.

innerHTML

=

JSONObject

.

slogan

script

body

html

Try it »

Click the "Try it yourself" button to view the online example.


Similarities with XML


Differences from XML


Why use JSON?

For AJAX applications, JSON is faster and easier to use than XML:

Using XML

Using JSON