Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Tutorials Json JSON in JavaScript

Related Tutorials


 
 

Share on Google+Share on Google+

JSON in JavaScript

Advertisement
JSON stands for JavaScript Object Notation that is a language independent text format which is fast and easy to understand.

JSON in JavaScript

     

JSON stands for JavaScript Object Notation that  is a language independent text format which is fast and easy to understand. That means it is really very simple and easy to learn without sparing much time. In another words we can say that JavaScript Object Notation is a lightweight data-interchange format that is completely language independent but with some conventions. 

So in this section of JSON tutorial we are going to discuss JSON  with JavaScript. 

Creating Object in JavaScript using JSON

We can create objects in JSON with JavaScript in many ways :

1. "var JSONObjectName ={};" will create an empty object. 

2. "var JSONObjectName= new Object();" will create a new Object.

3. "var JSONObjectName = { "name ":"amit", "age":23}; will create an Object with attribute name which contains value in String and age with numeric value.

Now by creating this object we can access attributes by only "." operator.

Here is the full example code for creating an Object in JavaScript using JSON:

ObjectJavaScript-JSON.htm

<html>
<head>
<title>
 Object creation in JSON in JavaScript
</title>
<script language="javascript" >
var JSONObject = {  "name" "Amit",
  "address"  "B-123 Bangalow",
  "age"  23
   "phone"   "011-4565763",
   "MobileNo"  0981100092
  };
document.write("<h2><font color='blue'>Name</font>::"
  
+JSONObject.name+"</h2>");  
document.write("<h2><font color='blue'>Address</font>::"
  
+JSONObject.address+"</h2>");  
document.write("<h2><font color='blue'>Age</font>::"
  
+JSONObject.age+"</h2>");  
document.write("<h2><font color='blue'>Phone No.</font>::"
   +JSONObject.phone+
"</h2>");  
document.write("<h2><font color='blue'>Mobile No.</font>::"
  
+JSONObject.MobileNo+"</h2>");  
</script>
</head>
<body>
<h3>Example of object creation in JSON in JavaScript</h3>
</body>
</html>


Output:
  


To run this JavaScript and JSON example you have to just run this ".htm" file on your browser.


Download code

     

Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: September 27, 2008

Related Tutorials

Discuss: JSON in JavaScript   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:4
jagdish
June 21, 2011
json

if json object can be created using .js file, whats the purpose of .json file ?
neeraj
September 24, 2011
Appreciating

The content which you have posted in this site is soo useful and i would like to appreciate the person who did this job and keep it up
santosh kumar
April 12, 2012
android

how to use in android program.
game pikachu
June 16, 2012
http://vgame.mobi

Thanks, it is basically useful for me
DMCA.com