<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html xmlns:yui="http://yuilibrary.com/rdf/1.0/yui.rdf#">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title>API: json JSON (YUI Library)</title>
<link rel="stylesheet" type="text/css" href="assets/reset-fonts-grids-min.css" />
<link rel="stylesheet" type="text/css" href="assets/api.css" />
<script type="text/javascript" src="assets/api-js"></script>
<script type="text/javascript" src="assets/ac-js"></script>
</head>
<body id="yahoo-com">
<div id="doc3" class="yui-t2">
<div id="hd">
<h1><a href="http://developer.yahoo.com/yui/" title="Yahoo! UI Library">Yahoo! UI Library</a></h1>
<h3>json <span class="subtitle">3.0.0b1</span></h3>
<a href="./index.html" title="Yahoo! UI Library">Yahoo! UI Library</a>
> <a href="./module_json.html" title="json">json</a>
> JSON
<form onsubmit="return false">
<div id="propertysearch">
Search: <input autocomplete="off" id="searchinput" />
<div id="searchresults">
</div>
</div>
</form>
</div>
<div id="bd">
<div id="yui-main">
<div class="yui-b">
<form action="#" name="yui-classopts-form" method="get" id="yui-classopts-form">
<fieldset>
<legend>Filters</legend>
<span class="classopts"><input type="checkbox" name="show_private" id="show_private" /> <label for="show_private">Show Private</label></span>
<span class="classopts"><input type="checkbox" name="show_protected" id="show_protected" /> <label for="show_protected">Show Protected</label></span>
<span class="classopts"><input type="checkbox" name="show_deprecated" id="show_deprecated" /> <label for="show_deprecated">Show Deprecated</label></span>
</fieldset>
</form>
<h2>
<code>static</code>
Class <b property="yui:name">JSON</b>
<span class="extends">
</span>
</h2>
<!-- class tree goes here -->
<div class="summary description" property="yui:description">
<p>The JSON module adds support for serializing JavaScript objects into
JSON strings and parsing JavaScript objects from strings in JSON format.</p>
<p>The JSON namespace is added to your YUI instance including static methods
Y.JSON.parse(..) and Y.JSON.stringify(..).</p>
<p>The functionality and method signatures follow the ECMAScript 5
specification. In browsers with native JSON support, the native
implementation is used.</p>
<p>The <code>json</code> module is a rollup of <code>json-parse</code> and
<code>json-stringify</code>.</p>
<p>As their names suggest, <code>json-parse</code> adds support for parsing
JSON data (Y.JSON.parse) and <code>json-stringify</code> 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.</p>
</div>
<div rel="yui:properties" resource="#properties">
<div class="section field details">
<h3 id="properties">Properties</h3>
<div class="content">
<div class="private" rel="yui:property" resource="#property__BRACKETS">
<h4><a name="property__BRACKETS" property="yui:name">_BRACKETS</a>
- <code>private <span property="yui:type">{RegExp}</span></code>
</h4>
<div class="detail">
<div class="description" property="yui:description">
Third step in the safety evaluation. Regex used to remove all open
square brackets following a colon, comma, or at the beginning of the
string.
</div>
</div>
<hr />
</div>
<div class="protected" rel="yui:property" resource="#property__CHARS">
<h4><a name="property__CHARS" property="yui:name">_CHARS</a>
- <code>protected static <span property="yui:type">{Object}</span></code>
</h4>
<div class="detail">
<div class="description" property="yui:description">
Character substitution map for common escapes and special characters.
</div>
</div>
<hr />
</div>
<div class="private" rel="yui:property" resource="#property__ESCAPES">
<h4><a name="property__ESCAPES" property="yui:name">_ESCAPES</a>
- <code>private <span property="yui:type">{RegExp}</span></code>
</h4>
<div class="detail">
<div class="description" property="yui:description">
First step in the safety evaluation. Regex used to replace all escape
sequences (i.e. "\\", etc) with '@' characters (a non-JSON character).
</div>
</div>
<hr />
</div>
<div class="private" rel="yui:property" resource="#property__INVALID">
<h4><a name="property__INVALID" property="yui:name">_INVALID</a>
- <code>private <span property="yui:type">{RegExp}</span></code>
</h4>
<div class="detail">
<div class="description" property="yui:description">
Final step in the safety evaluation. Regex used to test the string left
after all previous replacements for invalid characters.
</div>
</div>
<hr />
</div>
<div class="private" rel="yui:property" resource="#property__SIMPLE">
<h4><a name="property__SIMPLE" property="yui:name">_SIMPLE</a>
- <code>private <span property="yui:type">{RegExp}</span></code>
</h4>
<div class="detail">
<div class="description" property="yui:description">
Test for JSON string of simple data string, number, boolean, or null.
E.g. '"some string"', "true", "false", "null", or numbers "-123e+7"
This was needed for some WIP native implementations (FF3.1b2) but may be
unnecessary now.
</div>
</div>
<hr />
</div>
<div class="protected" rel="yui:property" resource="#property__SPECIAL_CHARS">
<h4><a name="property__SPECIAL_CHARS" property="yui:name">_SPECIAL_CHARS</a>
- <code>protected <span property="yui:type">{RegExp}</span></code>
</h4>
<div class="detail">
<div class="description" property="yui:description">
Regex used to capture characters that need escaping before enclosing
their containing string in quotes.
</div>
</div>
<hr />
</div>
<div class="private" rel="yui:property" resource="#property__UNICODE_EXCEPTIONS">
<h4><a name="property__UNICODE_EXCEPTIONS" property="yui:name">_UNICODE_EXCEPTIONS</a>
- <code>private <span property="yui:type">{RegExp}</span></code>
</h4>
<div class="detail">
<div class="description" property="yui:description">
Replace certain Unicode characters that JavaScript may handle incorrectly
during eval--either by deleting them or treating them as line
endings--with escape sequences.
IMPORTANT NOTE: This regex will be used to modify the input if a match is
found.
</div>
</div>
<hr />
</div>
<div class="private" rel="yui:property" resource="#property__VALUES">
<h4><a name="property__VALUES" property="yui:name">_VALUES</a>
- <code>private <span property="yui:type">{RegExp}</span></code>
</h4>
<div class="detail">
<div class="description" property="yui:description">
Second step in the safety evaluation. Regex used to replace all simple
values with ']' characters.
</div>
</div>
<hr />
</div>
<div class="private" rel="yui:property" resource="#property_Native">
<h4><a name="property_Native" property="yui:name">Native</a>
- <code>private <span property="yui:type">{Object}</span></code>
</h4>
<div class="detail">
<div class="description" property="yui:description">
Alias to native browser implementation of the JSON object if available.
</div>
</div>
<hr />
</div>
</div>
</div>
</div>
<div rel="yui:methods" resource="#methods">
<div class="section method details">
<h3 id="methods">Methods</h3>
<div class="content">
<div class="private" rel="yui:method" resource="#method__revive">
<h4>
<a name="method__revive">_revive</a></h4>
<div class="detail" >
<code>
private
MIXED
<strong property="yui:name">_revive</strong>
(
data
,
reviver
)
</code>
<div class="description" property="yui:description">
Traverses nested objects, applying a reviver function to each (key,value)
from the scope if the key:value's containing object. The value returned
from the function will replace the original value in the key:value pair.
If the value returned is undefined, the key will be omitted from the
returned object.
</div>
<div class="description">
<dl rel="yui:parameters">
<dt>Parameters:</dt>
<dd rel="yui:parameter">
<code><span property="yui:name">data</span>
<<span property="yui:type">MIXED</span>>
</code>
<span property="yui:description"> Any JavaScript data</span>
</dd>
<dd rel="yui:parameter">
<code><span property="yui:name">reviver</span>
<<span property="yui:type">Function</span>>
</code>
<span property="yui:description"> filter or mutation function</span>
</dd>
</dl>
<dl>
<dt>Returns:
<code property="yui:return">
MIXED
</code></dt>
<dd property="yui:returnInfo">The results of the filtered data</dd>
</dl>
</div>
</div>
<hr />
</div>
<div class="" rel="yui:method" resource="#method_dateToString">
<h4>
<a name="method_dateToString">dateToString</a></h4>
<div class="detail" >
<code>
static
String
<strong property="yui:name">dateToString</strong>
(
d
)
</code>
<div class="description" property="yui:description">
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.
</div>
<div class="description">
<dl rel="yui:parameters">
<dt>Parameters:</dt>
<dd rel="yui:parameter">
<code><span property="yui:name">d</span>
<<span property="yui:type">Date</span>>
</code>
<span property="yui:description"> The Date to serialize</span>
</dd>
</dl>
<dl>
<dt>Returns:
<code property="yui:return">
String
</code></dt>
<dd property="yui:returnInfo">stringified Date in UTC format YYYY-MM-DDTHH:mm:SSZ</dd>
</dl>
</div>
</div>
<hr />
</div>
<div class="private" rel="yui:method" resource="#method_escapeException">
<h4>
<a name="method_escapeException">escapeException</a></h4>
<div class="detail" >
<code>
private
String
<strong property="yui:name">escapeException</strong>
(
c
)
</code>
<div class="description" property="yui:description">
Replaces specific unicode characters with their appropriate \unnnn
format. Some browsers ignore certain characters during eval.
</div>
<div class="description">
<dl rel="yui:parameters">
<dt>Parameters:</dt>
<dd rel="yui:parameter">
<code><span property="yui:name">c</span>
<<span property="yui:type">String</span>>
</code>
<span property="yui:description"> Unicode character</span>
</dd>
</dl>
<dl>
<dt>Returns:
<code property="yui:return">
String
</code></dt>
<dd property="yui:returnInfo">the \unnnn escapement of the character</dd>
</dl>
</div>
</div>
<hr />
</div>
<div class="" rel="yui:method" resource="#method_parse">
<h4>
<a name="method_parse">parse</a></h4>
<div class="detail" >
<code>
static
MIXED
<strong property="yui:name">parse</strong>
(
s
,
reviver
)
</code>
<div class="description" property="yui:description">
Parse a JSON string, returning the native JavaScript representation.
</div>
<div class="description">
<dl rel="yui:parameters">
<dt>Parameters:</dt>
<dd rel="yui:parameter">
<code><span property="yui:name">s</span>
<<span property="yui:type">string</span>>
</code>
<span property="yui:description"> JSON string data</span>
</dd>
<dd rel="yui:parameter">
<code><span property="yui:name">reviver</span>
<<span property="yui:type">function</span>>
</code>
<span property="yui:description"> (optional) function(k,v) passed each key value
pair of object literals, allowing pruning or altering values</span>
</dd>
</dl>
<dl>
<dt>Returns:
<code property="yui:return">
MIXED
</code></dt>
<dd property="yui:returnInfo">the native JavaScript representation of the JSON string</dd>
</dl>
</div>
</div>
<hr />
</div>
<div class="" rel="yui:method" resource="#method_stringify">
<h4>
<a name="method_stringify">stringify</a></h4>
<div class="detail" >
<code>
static
string
<strong property="yui:name">stringify</strong>
(
o
,
w
,
ind
)
</code>
<div class="description" property="yui:description">
<p>Converts an arbitrary value to a JSON string representation.</p>
<p>Objects with cyclical references will trigger an exception.</p>
<p>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.</p>
<p>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.</p>
</div>
<div class="description">
<dl rel="yui:parameters">
<dt>Parameters:</dt>
<dd rel="yui:parameter">
<code><span property="yui:name">o</span>
<<span property="yui:type">MIXED</span>>
</code>
<span property="yui:description"> any arbitrary value to convert to JSON string</span>
</dd>
<dd rel="yui:parameter">
<code><span property="yui:name">w</span>
<<span property="yui:type">Array|Function</span>>
</code>
<span property="yui:description"> (optional) whitelist of acceptable object
keys to include, or a replacer function to modify the
raw value before serialization</span>
</dd>
<dd rel="yui:parameter">
<code><span property="yui:name">ind</span>
<<span property="yui:type">Number|String</span>>
</code>
<span property="yui:description"> (optional) indentation character or depth of
spaces to format the output.</span>
</dd>
</dl>
<dl>
<dt>Returns:
<code property="yui:return">
string
</code></dt>
<dd property="yui:returnInfo">JSON string representation of the input</dd>
</dl>
</div>
</div>
<hr />
</div>
</div>
</div>
</div>
<div rel="yui:events" resource="#events">
</div>
<div rel="yui:attributes" resource="#configattributes">
</div>
</div>
</div>
<div class="yui-b">
<div class="nav">
<div id="moduleList" class="module">
<h4>Modules</h4>
<ul class="content">
<li class=""><a href="module_anim.html" title="anim">anim</a></li>
<li class=""><a href="module_attribute.html" title="attribute">attribute</a></li>
<li class=""><a href="module_base.html" title="base">base</a></li>
<li class=""><a href="module_cache.html" title="cache">cache</a></li>
<li class=""><a href="module_classnamemanager.html" title="classnamemanager">classnamemanager</a></li>
<li class=""><a href="module_collection.html" title="collection">collection</a></li>
<li class=""><a href="module_console.html" title="console">console</a></li>
<li class=""><a href="module_console-filters.html" title="console-filters">console-filters</a></li>
<li class=""><a href="module_cookie.html" title="cookie">cookie</a></li>
<li class=""><a href="module_dataschema.html" title="dataschema">dataschema</a></li>
<li class=""><a href="module_datasource.html" title="datasource">datasource</a></li>
<li class=""><a href="module_datatype.html" title="datatype">datatype</a></li>
<li class=""><a href="module_dd.html" title="dd">dd</a></li>
<li class=""><a href="module_dom.html" title="dom">dom</a></li>
<li class=""><a href="module_dump.html" title="dump">dump</a></li>
<li class=""><a href="module_event.html" title="event">event</a></li>
<li class=""><a href="module_event-custom.html" title="event-custom">event-custom</a></li>
<li class=""><a href="module_event-simulate.html" title="event-simulate">event-simulate</a></li>
<li class=""><a href="module_history.html" title="history">history</a></li>
<li class=""><a href="module_imageloader.html" title="imageloader">imageloader</a></li>
<li class=""><a href="module_io.html" title="io">io</a></li>
<li class="selected"><a href="module_json.html" title="json">json</a></li>
<li class=""><a href="module_node.html" title="node">node</a></li>
<li class=""><a href="module_node-focusmanager.html" title="node-focusmanager">node-focusmanager</a></li>
<li class=""><a href="module_node-menunav.html" title="node-menunav">node-menunav</a></li>
<li class=""><a href="module_oop.html" title="oop">oop</a></li>
<li class=""><a href="module_overlay.html" title="overlay">overlay</a></li>
<li class=""><a href="module_plugin.html" title="plugin">plugin</a></li>
<li class=""><a href="module_profiler.html" title="profiler">profiler</a></li>
<li class=""><a href="module_queue.html" title="queue">queue</a></li>
<li class=""><a href="module_slider.html" title="slider">slider</a></li>
<li class=""><a href="module_stylesheet.html" title="stylesheet">stylesheet</a></li>
<li class=""><a href="module_substitute.html" title="substitute">substitute</a></li>
<li class=""><a href="module_test.html" title="test">test</a></li>
<li class=""><a href="module_widget.html" title="widget">widget</a></li>
<li class=""><a href="module_widget-position.html" title="widget-position">widget-position</a></li>
<li class=""><a href="module_widget-position-ext.html" title="widget-position-ext">widget-position-ext</a></li>
<li class=""><a href="module_widget-stack.html" title="widget-stack">widget-stack</a></li>
<li class=""><a href="module_widget-stdmod.html" title="widget-stdmod">widget-stdmod</a></li>
<li class=""><a href="module_yui.html" title="yui">yui</a></li>
</ul>
</div>
<div id="classList" class="module">
<h4>Classes</h4>
<ul class="content">
<li class="selected"><a href="JSON.html" title="JSON">JSON</a></li>
</ul>
</div>
<div id="fileList" class="module">
<h4>Files</h4>
<ul class="content">
<li class=""><a href="json-parse.js.html" title="json-parse.js">json-parse.js</a></li>
<li class=""><a href="json-stringify.js.html" title="json-stringify.js">json-stringify.js</a></li>
</ul>
</div>
<div id="propertyList" class="module">
<h4>Properties</h4>
<ul class="content">
<li class="private"><a href="#property__BRACKETS" title="_BRACKETS">_BRACKETS</a></li>
<li class="protected"><a href="#property__CHARS" title="_CHARS">_CHARS</a></li>
<li class="private"><a href="#property__ESCAPES" title="_ESCAPES">_ESCAPES</a></li>
<li class="private"><a href="#property__INVALID" title="_INVALID">_INVALID</a></li>
<li class="private"><a href="#property__SIMPLE" title="_SIMPLE">_SIMPLE</a></li>
<li class="protected"><a href="#property__SPECIAL_CHARS" title="_SPECIAL_CHARS">_SPECIAL_CHARS</a></li>
<li class="private"><a href="#property__UNICODE_EXCEPTIONS" title="_UNICODE_EXCEPTIONS">_UNICODE_EXCEPTIONS</a></li>
<li class="private"><a href="#property__VALUES" title="_VALUES">_VALUES</a></li>
<li class="private"><a href="#property_Native" title="Native">Native</a></li>
</ul>
</div>
<div id="methodsList" class="module">
<h4>Methods</h4>
<ul class="content">
<li class="private"><a href="#method__revive" title="_revive">_revive</a></li>
<li class=""><a href="#method_dateToString" title="dateToString">dateToString</a></li>
<li class="private"><a href="#method_escapeException" title="escapeException">escapeException</a></li>
<li class=""><a href="#method_parse" title="parse">parse</a></li>
<li class=""><a href="#method_stringify" title="stringify">stringify</a></li>
</ul>
</div>
</div>
</div>
</div>
<div id="ft">
<hr />
Copyright © 2009 Yahoo! Inc. All rights reserved.
</div>
</div>
<script type="text/javascript">
ALL_YUI_PROPS = [{"access": "private", "host": "JSON", "name": "_BRACKETS", "url": "JSON.html#property__BRACKETS", "type": "property"}, {"access": "protected", "host": "JSON", "name": "_CHARS", "url": "JSON.html#property__CHARS", "type": "property"}, {"access": "", "host": "JSON", "name": "dateToString", "url": "JSON.html#method_dateToString", "type": "method"}, {"access": "private", "host": "JSON", "name": "escapeException", "url": "JSON.html#method_escapeException", "type": "method"}, {"access": "private", "host": "JSON", "name": "_ESCAPES", "url": "JSON.html#property__ESCAPES", "type": "property"}, {"access": "private", "host": "JSON", "name": "_INVALID", "url": "JSON.html#property__INVALID", "type": "property"}, {"access": "private", "host": "JSON", "name": "Native", "url": "JSON.html#property_Native", "type": "property"}, {"access": "", "host": "JSON", "name": "parse", "url": "JSON.html#method_parse", "type": "method"}, {"access": "private", "host": "JSON", "name": "_revive", "url": "JSON.html#method__revive", "type": "method"}, {"access": "private", "host": "JSON", "name": "_SIMPLE", "url": "JSON.html#property__SIMPLE", "type": "property"}, {"access": "protected", "host": "JSON", "name": "_SPECIAL_CHARS", "url": "JSON.html#property__SPECIAL_CHARS", "type": "property"}, {"access": "", "host": "JSON", "name": "stringify", "url": "JSON.html#method_stringify", "type": "method"}, {"access": "private", "host": "JSON", "name": "_UNICODE_EXCEPTIONS", "url": "JSON.html#property__UNICODE_EXCEPTIONS", "type": "property"}, {"access": "private", "host": "JSON", "name": "_VALUES", "url": "JSON.html#property__VALUES", "type": "property"}];
</script>
</body>
</html>