This version of the Delicious website will be shutdown by April 2014.
We encourage users to switch to the new Delicious site at http://delicious.com , which features a responsive design for mobile and tablet users, offline access, faster loading, and more.

Yahoo! UI Library: JSON utility

http://developer.yahoo.com/yui/json/

The JSON Utility provides methods for translating data to and from JavaScript Object Notation. JSON is a safe, efficient, and reliable data interchange format. This utility defers to native JSON methods in browsers that have support, and provides JavaScript implementations that conform to the ECMAScript 5 specification for those that don't yet.

Upgrade Notes

As of version 2.8.0, browser native

JSON.parse

and

JSON.stringify

will be used if present. The native implementations are much faster and safer than any implementation done in JavaScript.

In versions prior to 2.8, the signature and behavior of

YAHOO.lang.JSON.stringify

differed slightly from the reference implementation at JSON.org and the ECMAScript version 5 specification that grew from that. In order to leverage native methods as browsers adopt the ECMAScript 5 spec, the YUI implementation of

stringify

had to change so the behavior would be consistent across browsers with and without native JSON support.

Specifically, the

stringify

behavior that has changed from 2.7.0 to 2.8.0 is:

Cyclical object references are no longer replaced with

null

, but now throw an Error. It is therefore recommended to wrap both

parse

and

stringify

calls in

try/catch

blocks.

The third parameter no longer limits the depth of object serialization, but is now used to trigger formatted output.

Objects with a

toJSON

method will be first transformed using this method.

Object keys are no longer sorted alphabetically. This is possible to do with a replacer function.

Overriding

YAHOO.lang.JSON.dateToString

is no longer recommended because the default ISO 8601 serialization is defined in the spec. If Dates must be formatted differently, either preprocess the data or set

useNativeStringify

to

false

Comments