JSON in JavaScript

Source

var jsonObj = {
 'firstName' : 'Krijn',
 'lastName' : 'Hoetmer',
 'website' : {
  'uri' : 'http://krijnhoetmer.nl/',
  'stuff' : {
   'CSS' : 'Cascading Style Sheets',
   'HTML' : 'HyperText Markup Language',
   'JS' : 'JavaScript'
  },
  'testAlert' : function() {
   alert(this.firstName + ' ' + this.lastName);
  }
 },
 'myAgeAtTheMomentOfWritingThis' : 20,
 'testAlert' : function() {
  alert(this.firstName + ' ' + this.lastName);
 }
};

Method calls

.. onclick="jsonObj.testAlert();"..

.. onclick="jsonObj.website.testAlert();"..

(Watch out with the this keyword.)


Walking the object tree with JavaScript

[Requires JavaScript]

Home - More stuff