YUI recommends YUI3.
YUI 2 has been deprecated since 2011. This site acts as an archive for files and documentation.
This documentation is no longer maintained.
static
Class YAHOO.lang.JSON
private static {RegExp}
private static {Object}
private static {RegExp}
private static {RegExp}
private {RegExp}
private static {RegExp}
private static {RegExp}
static Boolean
static Boolean
private
String
_prepare
(
s
)
s
<String>
parse input
String
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
static
boolean
isSafe
(
str
)
str
<String>
JSON string to be tested
boolean
static
boolean
isValid
(
str
)
Four step determination whether a string is safe to eval. In three steps, escape sequences, safe values, and properly placed open square brackets are replaced with placeholders or removed. Then in the final step, the result of all these replacements is checked for invalid characters.
This is an alias for isSafe.
str
<String>
JSON string to be tested
boolean
static
MIXED
parse
(
s
,
reviver
)
Parse a JSON string, returning the native JavaScript representation.
When lang.JSON.useNativeParse is true, this will defer to the native JSON.parse if the browser has a native implementation. Otherwise, a JavaScript implementation based on http://www.json.org/json2.js is used.
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
,
space
)
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.
When lang.JSON.useNativeStringify is true, this will defer to the native JSON.stringify if the browser has a native implementation. Otherwise, a JavaScript implementation is used.
o
<MIXED>
any arbitrary object to convert to JSON string
w
<Array|Function>
(optional) whitelist of acceptable object keys
to include OR a function(value,key) to alter values
before serialization
space
<Number|String>
(optional) indentation character(s) or
depthy of spaces to format the output
string
Date
stringToDate
(
str
)
str
<String>
String serialization of a Date