Documentation Home  -  API Home  -  system function

JSON

Version 1

The JSON library provides methods to convert Javascript objects into Javascript strings and vice-versa.

This library supplies a copy of the JSON Javascript implementation by Douglas Crockford. The source code to this library is available online at http://www.json.org/json2.js. Our system library is a convenience to avoid the need for you to copy and paste this source code into your own applications.

system('json',1);

var today = new Date();
var s_today = JSON.stringify(today);
database.save('today',s_today);

var s_yesterday = database.load('yesterday');
if( s_yesterday ) {
   var yesterday = JSON.parse(s_yesterday);
}

These methods are particularly useful when storing object information in the database (which only accepts string, number, and boolean values) as above. They are also helpful when creating or acting as a client to JSON based AJAX services.

For the full behaviour and implications of the JSON standard see the http://json.org/ website.

Note, this version of the json system library imports version 1 of the patches library automatically.

Functions

JSON.stringify(object)

function
Parameters
objectobjectThe object to encode into a JSON string
Returns
stringThe object encoded as a JSON string

Takes an object and encodes it as a string according to the JSON specification.

JSON.parse(text)

function
Parameters
textstringThe JSON string to decode
Returns
objectThe object constructed from the supplied JSON string

Takes an object encoded according to the JSON specification and decodes it into a Javascript object.