Not logged in

This pages describes the JSON driver. For API details see reference.


JSON (JavaScript Object Notation) is an open standard format that uses human-readable text to transmit data objects consisting of attribute–value pairs. It is the primary means of exchanging data with web-browsers.

The JSON object provides the following methods:

function stringify(val:any, strict:boolean=true):string

The stringify() method converts a javascript data object to a string:

var obj = { a:1, b:2, c:"able", d:[ 1, 2, 3 ] };
var str = JSON.stringify(obj);
//RETURNS: '{"a":1, "b":2, "c":"able", "d":[1,2,3]}';

function parse(str:string, strict:boolean=true):any

The parse() method converts a string into javascript data:

var str = '{"a":1, "b":2, "c":"able", "d":[1,2,3]}';
var obj = JSON.parse(str);
//RETURNS: { a:1, b:2, c:"able", d:[ 1, 2, 3 ] }

When strict is false then parse() that does not require quoting of names.

var str = '{a:1, b:2, c:"able", d:[1,2,3]}';
var obj = JSON.parse(str, false);

Non-strict parsing is particularly helpful when encoding JSON in C.