The goog.json Namespace

The goog.json.EvalJsonProcessor Class

A class that parses and stringifies JSON using eval (as implemented in goog.json). Adapts {@code goog.json} to the {@code goog.json.Processor} interface. … more

The goog.json.NativeJsonProcessor Class

A class that parses and stringifies JSON using the browser's built-in JSON library, if it is avaliable. Note that the native JSON api has subtle differences across browsers, so use this implementation with care. See json_test#assertSerialize for details on the differences from goog.json. This implementation is signficantly faster than goog.json, at least on Chrome. See json_perf.html for a perf test showing the difference. … more

The goog.json.Processor Interface

An interface for JSON parsing and serialization. @interface … more

.Replacer

JSON replacer, as defined in Section 15.12.3 of the ES5 spec. TODO(nicksantos): Array should also be a valid replacer.

@typedef
{function(this:Object, string, *): *}

.Reviver

JSON reviver, as defined in Section 15.12.2 of the ES5 spec.

@typedef
{function(this:Object, string, *): *}

The goog.json.Serializer Class

Class that is used to serialize JSON objects to a string. … more

.parse(s)

Parses a JSON string and returns the result. This throws an exception if the string is an invalid JSON string. Note that this is very slow on large strings. If you trust the source of the string then you should use unsafeParse instead.

s {*}
The JSON string to parse.
returns {Object}
The object generated from the JSON string.

.serialize(object, opt_replacer)

Serializes an object or a value to a JSON string.

object {*}
The object to serialize.
opt_replacer {?goog.json.Replacer=}
A replacer function called for each (key, value) pair that determines how the value should be serialized. By defult, this just returns the value and allows default serialization to kick in.
returns {string}
A JSON string representation of the input.
@throws
Error if there are loops in the object graph.

.unsafeParse(s)

Parses a JSON string and returns the result. This uses eval so it is open to security issues and it should only be used if you trust the source.

s {string}
The JSON string to parse.
returns {Object}
The object generated from the JSON string.