Yahoo! UI Library

json  2.5.1

Yahoo! UI Library > json > YAHOO.lang.JSON

Show Private Show Protected

static Class YAHOO.lang.JSON

Provides methods to parse JSON strings and convert objects to JSON strings.

Properties

Methods

dateToString

static String dateToString ( d )
Serializes a Date instance as a UTC date string. Used internally by stringify. Override this method if you need Dates serialized in a different format.
Parameters:
d <Date> The Date to serialize
Returns: String
stringified Date in UTC format YYYY-MM-DDTHH:mm:SSZ

isValid

static boolean isValid ( str )
Four step determination whether a string is valid JSON. 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.
Parameters:
str <String> JSON string to be tested
Returns: boolean
is the string safe for eval?

parse

static MIXED parse ( s , filter )
Parse a JSON string, returning the native JavaScript representation. Only minor modifications from http://www.json.org/json.js.
Parameters:
s <string> JSON string data
filter <function> (optional) function(k,v) passed each key value pair of object literals, allowing pruning or altering values
Returns: MIXED
the native JavaScript representation of the JSON string

stringify

static string stringify ( o , w , d )
Converts an arbitrary value to a JSON string representation. Cyclical object or array references are replaced with null. If a whitelist is provided, only matching object keys will be included. If a depth limit is provided, objects and arrays at that depth will be stringified as empty.
Parameters:
o <MIXED> any arbitrary object to convert to JSON string
w <Array> (optional) whitelist of acceptable object keys to include
d <number> (optional) depth limit to recurse objects/arrays (practical minimum 1)
Returns: string
JSON string representation of the input

stringToDate

Date stringToDate ( str )
Reconstitute Date instances from the default JSON UTC serialization. Reference this from a parse filter function to rebuild Dates during the parse operation.
Parameters:
str <String> String serialization of a Date
Returns: Date


Copyright © 2007 Yahoo! Inc. All rights reserved.