static
Class JSON
The JSON module adds support for serializing JavaScript objects into JSON strings and parsing JavaScript objects from strings in JSON format.
The JSON namespace is added to your YUI instance including static methods Y.JSON.parse(..) and Y.JSON.stringify(..).
The functionality and method signatures follow the ECMAScript 5 specification. In browsers with native JSON support, the native implementation is used.
The json
module is a rollup of json-parse
and
json-stringify
.
As their names suggest, json-parse
adds support for parsing
JSON data (Y.JSON.parse) and json-stringify
for serializing
JavaScript data into JSON strings (Y.JSON.stringify). You may choose to
include either of the submodules individually if you don't need the
complementary functionality, or include the rollup for both.
private {RegExp}
private {RegExp}
private {RegExp}
private {RegExp}
private {RegExp}
static Boolean
static Boolean
private
MIXED
_revive
(
data
,
reviver
)
data
<MIXED>
Any JavaScript data
reviver
<Function>
filter or mutation function
MIXED
static
String
dateToString
(
d
)
d
<Date>
The Date to serialize
String
private
String
escapeException
(
c
)
c
<String>
Unicode character
String
static
MIXED
parse
(
s
,
reviver
)
s
<string>
JSON string data
reviver
<function>
(optional) function(k,v) passed each key value
pair of object literals, allowing pruning or altering values
MIXED
static
string
stringify
(
o
,
w
,
ind
)
Converts an arbitrary value to a JSON string representation.
Objects with cyclical references will trigger an exception.
If a whitelist is provided, only matching object keys will be included. Alternately, a replacer function may be passed as the second parameter. This function is executed on every value in the input, and its return value will be used in place of the original value. This is useful to serialize specialized objects or class instances.
If a positive integer or non-empty string is passed as the third parameter, the output will be formatted with carriage returns and indentation for readability. If a String is passed (such as "\t") it will be used once for each indentation level. If a number is passed, that number of spaces will be used.
o
<MIXED>
any arbitrary value to convert to JSON string
w
<Array|Function>
(optional) whitelist of acceptable object
keys to include, or a replacer function to modify the
raw value before serialization
ind
<Number|String>
(optional) indentation character or depth of
spaces to format the output.
string