JSON - Introduction

JSON - Evaluates to JavaScript Objects

The JSON group is linguistically indistinguishable to the code for making JavaScript objects.

Because of this comparability, rather than utilizing a parser (like XML does), a JavaScript program can utilize standard JavaScript capacities to change over JSON information into local JavaScript objects.

Try it Yourself

With our supervisor, you can alter JavaScript code on the web and snap on a catch to see the result:

JSON Example

<!DOCTYPE html>

<h2>JSON Object Creation in JavaScript</h2>

<p id="demo"></p>

var content = '{"name":"John Johnson","street":"Oslo West 16","phone":"555 1234567"}';

var obj = JSON.parse(text);

document.getElementById("demo").innerHTML =
obj.name + "<br>" +
obj.street + "<br>" +


 Much Like XML Because

  • Both JSON and XML is "self describing" (human readable)
  • Both JSON and XML is various leveled (values inside values)
  • Both JSON and XML can be parsed and utilized by bunches of programming languages
  • Both JSON and XML can be brought with a XMLHttpRequest

Much Unlike XML Because

  • JSON doesn't utilize end tag
  • JSON is shorter
  • JSON is speedier to peruse and write
  • JSON can utilize arrays

The greatest contrast is:

 XML must be parsed with a XML parser, JSON can be parsed by a standard JavaScript work.


For AJAX applications, JSON is quicker and less demanding than XML:

Using XML

  • Fetch a XML document
  • Use the XML DOM to circle through the document
  • Extract qualities and store in variables

Using JSON

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