JSON Object - Powerful Javascript Notation Overview

I believe most of you have heard about using XML to store data. However, using JSON object to store data in Javascript is the most convenient way as JSON object is native in Javascript programming. An example of JSON object is as following

var myJSON = {
      browser: "Firefox 2.0.16",
      platform: "Mac OS X",
      ipaddress: "127.0.0.1"
}

In myJSON object, we only store 3 pieces of data naming browser, platform and ipaddress. However, you can put in as many data as you would like to store. Each piece of information is constructed by 2 parts: a unique name of data within JSON object (e.g. browser, platform, ipaddress) and the data itself ( e.g. “Firefox 2.0.16″, “Mac OS X”, “127.0.0.1″ ).

Additionally, JSON object can also be nested. For example

var myJSON = {
      browser: "Firefox 2.0.16",
      platform: "Mac OS X",
      ipaddress: "127.0.0.1"
      os: {
            name: "Mac OS",
            version: "X",
            cpu: "2.4 ghz"
      }
}

os itself is another JSON object nested within myJSON object

You can also store an array in a JSON object, for example

var myJSON = {
      browser: "Firefox 2.0.16",
      platform: "Mac OS X",
      ipaddress: "127.0.0.1"
      os: {
            name: "Mac OS",
            version: "X",
            cpu: "2.4 ghz",
            compatible_browsers: ["Firefox", "Safari", "Opera"]
      }
}

In this example, compatible_browsers is an array of String

A Javascript array itself is also considered as a JSON object but not vice versa, for example arrayJSON itself is an array and a JSON object,

var arrayJSON = ["Firefox", "Safari", "Opera"]

You can even write JSON object as following

var myPlatformsJSON = [
      windows: {
            default_browser: "Internet Explorer",
            compatible_browsers: ["Internet Explorer", "Firefox",
                                                       "Safari Beta", "Opera"],
            version: "XP"
      },
      linux: {
            default_browser: "Firefox",
            compatible_browsers: ["Firefox", "Conqueror", "Opera"],
            version: "Ubuntu"
      },
      macOS: {
            default_browser: "Safari",
            compatible_browsers: ["Safari", "Firefox", "Opera"],
            version: "X"
      }
]

By using JSON object, you could store any types of data. Additionally, the data in JSON object is accessible in a surprisingly easy way, which makes JSON object becomes so powerful and extremely popular in AJAX transaction.

Del.icio.us | Digg it | StumbleUpon | BlinkBits | Furl | Ma.gnolia | Newsvine | Reddit

One Response to “JSON Object - Powerful Javascript Notation Overview”

  1. Wendy says:

    Wow, it’s so complicated that it makes my eyes blurry. But it’s nice to know the fact that JSON object comes this handy. Looking forward to the continuation of this article :-)

Leave a Reply