Client Class JSON

The JSON class provided here is Douglas Crockfords Json2 library embedded into this library for old browser clients that don't support JSON if the JSON library is not natively available in the browser.

This class also extends the native JSON interface to support date parsing both in browser standard ISO format (default) and Microsoft's custom date encoding format.

This class is not loaded if a browser that natively supports JSON is used as most modern browsers do. The interface to this JSON class matches native JSON classes. It is based on Douglas Crockford's JSON JavaScript code with a number of modifications to handle date formatting in ISO and Microsoft formats. The parse() method checks for invalid characters in the JSON string before parsing and disallows executable code.

var person = { Name: "Rick", Company: "West Wind", Entered: new Date() };

var json = JSON.stringify(person);

//{"Name":"Rick","Company":"West Wind","Entered":""2009-01-03T18:10:00Z""}

var copied = JSON.parseWithDates(json);
alert( copied.Entered  + " - " + copied.Name);

Dates are formatted in ISO date format by default.

Class Members



Converts an ISO or MS AJAX style date into a date object.



Parses a JSON string into a JavaScript value or object. This version throws an exception if parsing fails.



Parses a JSON string into a value or object.



Serializes a JavaScript object into a JSON string.



Use this function to globally replace the JSON date parser with a data aware JSON parser. Rather than returning dates as ISO (or MSAjax) strings, this replacement converts these date strings into native JavaScript dates.



Determines whether MSAjax dates are parsed as part of the date parsing operations performed by this extension class. Defaults to false.

See also:

Class JSON

© West Wind Technologies, 1996-2022 • Updated: 02/27/16
Comment or report problem with topic