Javascript JSON Object

JavaScript Object Notation - JSON is a very lightweight data-interchange format. The most improtant thing about JSON is, easy to read and write. It is language-independent data exchange format that makes you easy to easily share information between veriety of our systems and devices, regardless of technology.

JSON is a simple text (key-value) that is completely language independent but uses conventions that are familiar to programmers of C#, Java, JavaScript and many others. These make JSON an ideal data-interchange language. Here is an example of JSON data:

Javascript Simple JSON Object Example

<html>
<head>
<title>My first JSON Object Code</title>
<SCRIPT LANGUAGE="JavaScript">
var jsonData=
{
     "firstName": "Jimi",
     "lastName": "Scotts",
     "address": "12-13-283/A1"
 }
 document.write(jsonData.firstName + ' ' + jsonData.lastame);
 </SCRIPT>
 </HEAD>
<BODY>
</BODY>
</HTML>

Javascript Array In JSON Object Example

<html>
<head>
<title>My first JSON Object Code</title>
<SCRIPT LANGUAGE="JavaScript">
 var jsonData={"customer":[
        {
		 "firstName": "Jimi",
		 "lastName": "Scotts",
		 "address": "12-13-283/A1"
		 },
        {
		 "firstName": "Tom",
		 "lastName": "Scotts",
		 "address": "12-13-284/A2"
		 }
]}

 document.write(jsonData.customer[0].firstName + ' ' + jsonData.customer[0].lastame);
 </SCRIPT>
</HEAD>
<BODY>
</BODY>
</HTML>

Javascript Read JSON From File Example

<html>
<head>
<title>My first JSON Object Code</title>
<script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
<SCRIPT LANGUAGE="JavaScript">

$.getJSON('javascript-json.json', function(data) {
	var displayList="<ul>";
	for (var i in jsonData.customer) {
		output+="<li>" + jsonData.customer[i].firstName + " " + jsonData.customer[i].lastName + "</li>";
	}

 displayList+="</ul>";
 document.write(displayList);
 
</SCRIPT>
</HEAD>
<BODY>
</BODY>
</HTML>