RobertoBifulco.it

  • topics
  • projects
  • il gatto
  • account
Home › Rich Client Web Applications: the future so near › Chapter II

II.1Data serialization

Roberto Bifulco — Mon, 02/11/2008 - 15:06

The biggest feature of AJAX is the possibility to fetch simple data that page's scripts organize for the presentation, cutting all the overhead linked to the formatting information that are embedded in HTML texts. Moreover, if the future is the building of rich client applications, the requested informations are not text, but a mix of different formats like numbers, strings, dates, and so on.

For this reason a serialization language is needed. In the beginning the serialization language was XML, and it is widely used yet. While XML is a great meta-language, it has two big downsides:

  • the great number of meta-information characters that in a small request could overcame the real information characters;

  • the need to implement an XML parser through Javascript, that as every interpreted language, pay a huge price in terms of elaboration time and resource usage.

These downsides are enough to search a new serialization language that actually is the JSON language.

“JSON (JavaScript Object Notation) is a lightweight data-interchange format. It is easy for humans to read and write. It is easy for machines to parse and generate. It is based on a subset of the JavaScript Programming Language, Standard ECMA-262 3rd Edition - December 1999. JSON is a text format that is completely language independent but uses conventions that are familiar to programmers of the C-family of languages, including C, C++, C#, Java, JavaScript, Perl, Python, and many others”[10].


 


Figure 4: The JSON grammar


The great advantage of JSON is that uses a subset of the Javascript language, in particular, JSON share the Javascript data structure representation. This means that the parsing of a JSON string can be done through the native-language written Javascript browser's parser, with a really high performance.

Some of the most famous AJAX applications use JSON for data serialization, an example are the already mentioned Gmail and Documents&SpreadSheets, but also Yahoo groups and others.

An example of JSON encoded text is the next:

{"widget": {

    "debug": "on",
    "window": {
        "title": "Sample Konfabulator Widget",
        "name": "main_window",

        "width": 500,
        "height": 500
    },
    "image": { 
        "src": "Images/Sun.png",

        "name": "sun1",
        "hOffset": 250,
        "vOffset": 250,
        "alignment": "center"

    },
    "text": {
        "data": "Click Here",
        "size": 36,

        "style": "bold",
        "name": "text1",
        "hOffset": 250,
        "vOffset": 100,

        "alignment": "center",
        "onMouseUp": "sun1.opacity = (sun1.opacity / 100) * 90;"
    }
}}    

The same text expressed as XML:

<widget>
    <debug>on</debug>
    <window title="Sample Konfabulator Widget">
        <name>main_window</name>

        <width>500</width>
        <height>500</height>
    </window>
    <image src="Images/Sun.png" name="sun1">

        <hOffset>250</hOffset>
        <vOffset>250</vOffset>
        <alignment>center</alignment>
    </image>

    <text data="Click Here" size="36" style="bold">
        <name>text1</name>
        <hOffset>250</hOffset>

        <vOffset>100</vOffset>
        <alignment>center</alignment>
        <onMouseUp>
            sun1.opacity = (sun1.opacity / 100) * 90;
        </onMouseUp>

    </text>
</widget>

Other examples are in http://www.json.org/example.html .

‹ Chapter II up II.2AJAX tools ›
  • Printer-friendly version

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.

Rich Client Web Applications: the future so near

  • Preface
  • Introduction
  • Chapter I
  • Chapter II
    • II.1Data serialization
    • II.2AJAX tools
  • Chapter III
    • III.1Attack Types
      • III.1.1Cross Site Scripting (XSS)
      • III.1.2Cross Site Request Forgeries (CSRF)
      • III.1.3JSON Hijacking
  • Chapter IV
    • IV.1RPC requirements
    • IV.2GJPR
  • Chapter V
    • V.1Architecture
    • V.2The polling problem
  • Bibliography
  • topics
  • projects
  • il gatto
  • account