Java JSON Tutorial - JSON Introduction

JSON stands for JavaScript Object Notation. It is a lightweight, text-based, human-readable data format.

JSON is Language independent.

The JSON format is specified in RFC 4627

The official Internet media type for JSON is application/json. The JSON filename extension is .json.

JSON is often used with JavaScript based application.

JSON format is used for serializing and transmitting data over network.

JSON Example

The following JSON data shows how to store Books information.

    "book": [
       "language": "Java",
       "edition": "third",
       "author": ""
       "language": "JSON",
       "edition": "second"
       "author": "Jack"

Output JSON

The following code shows how to output JSON format data using Javascript. Save the code as json.htm:

<script language="javascript" >
  var object1 = { "language" : "Java", "author"  : "" };
  document.write("<h3>Language = " + object1.language+"</h3>");  
  document.write("<h3>Author = " +"</h3>");   

  var object2 = { "language" : "JSON", "author"  : "Jack" };
  document.write("<h3>Language = " + object2.language+"</h3>");  
  document.write("<h3>Author = " +"</h3>");   
  document.write("<hr />");
  document.write(object2.language +"<br/> "+;
  document.write("<hr />");

JSON Comparison with XML

JSON and XML are both human readable, language independent data formats.

XML is more verbose than JSON and used to describe structured data.

JSON supports arrays.

The following JSON specify the company and its name.

   "company": "",
   "name": "Java2s"

Rewrite the above JSON in XML as follows.