O'Reilly logo

HTML5 Data and Services Cookbook by Mite Mitreski, Gorgi Kosev

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Deserializing JSON to JavaScript objects

The simplest of all cases is reading JSON data into JavaScript objects. Data formatted in this way is of lightweight and additionally it is a subset of JavaScript. There are several ways to read this data and we will take a look at how this can be done by creating a simple JSON snippet and then converting it to JavaScript objects.

How to do it...

This example will be simple enough to be a script in an HTML file or even executed on a firebug or developer tools console:

  1. We first need the following serialized JSON string:
    var someJSONString = '{"comment":"JSON data usually is retrieved from server","who":"you"}';
  2. There are few different ways to do this without adding external JavaScript dependency, one is through ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required