JavaScript
  Home arrow JavaScript arrow Page 4 - JSON Basics
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
JAVASCRIPT

JSON Basics
By: Jayaram Krishnaswamy
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 7
    2007-02-28

    Table of Contents:
  • JSON Basics
  • JSON basics
  • Array
  • JSON and XML
  • Root element with students and their attributes

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    JSON Basics - JSON and XML


    (Page 4 of 5 )

    JSON is minimal textual representation of data as compared to the "verbose" XML, which makes equivalent XML much larger than JSON. Well, both are textual, but JSON is more so than XML with all its "angularities." This is not to put down XML but just to highlight the obvious. This has obvious implications for AJAX, and more often JSON is the preferred data format in which AJAX results are received. Everything in XML is a string but JSON has types as discussed earlier.

    JSON equivalent of XML

    In my previous tutorials, XML Islands and XML Responses and AJAX, the file webstudents.xml was used for illustration. The same file will be represented as a JSON object in this section. The file is reproduced here for reference. In writing down the equivalence only the root element and its children are considered. Here is the listing of webstudents.xml.

    <wclass>
    <!--My students who took web programming class with me-->
    <student id="1">
    <name>Linda Jones</name> 
    <legacySkill>Access, VB5.0</legacySkill>
    </student>
    <student id="2">
    <name>Adam Davidson</name> 
    <legacySkill>Cobol, MainFrame</legacySkill>
    </student>
    <student id="3">
    <name>Charles Boyer</name> 
    <legacySkill>HTML, Photoshop</legacySkill>
    </student>
    <student id="4">
    <name>Charles Mann</name> 
    <legacySkill>Cobol, MainFrame</legacySkill>
    </student>
    </wclass> 

    The rules in this conversion are simple. The root element will be the main object, and the three student nodes will form an array. Each array element will be a student object with its own attributes as a string value pair. If you keep the following syntax  in your cross-hairs it will be easy to follow the listing.

    Object:
    var obj={key1:value1, key2:value2 ,key3:value3};
    Array:
    var Arr=[valueA, valueB, valueC];
    

    The XML document has both simple and complex types and this is developed piecewise to make the explanation easy to understand.

    More JavaScript Articles
    More By Jayaram Krishnaswamy


       · JSON has elements (data types, objects, arrays) similar to what one finds in...
     

    JAVASCRIPT ARTICLES

    - Comparing Fields and Customizing Error Messa...
    - Checking Numbers and File Extensions with jQ...
    - Validating Digits and Dates with jQuery`s Va...
    - Validating Ranges, Emails, and URLs with jQu...
    - More Uses for the jQuery Tooltip Plug-in`s b...
    - Building Image-Based Tooltips with the jQuer...
    - Using the jQuery Tooltip Plug-in`s bodyHandl...
    - Using Rangelength, Min and Max with the Vali...
    - Using Minlength and Maxlength with the Valid...
    - Modifying Tooltip Coordinates with the jQuer...
    - Applying a Fade Out Effect with the jQuery T...
    - Tracking Mouse Movements with the jQuery Too...
    - Checking Online Forms with the Validator jQu...
    - Nested JavaScript Functions as Objects
    - The jQuery Tooltip Plug-in







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek