format.JsonPrettyPrinter Extends
Formats a JSON object as a string, properly indented for display. Supports displaying the string as text or html. Users can also specify their own set of delimiters for different environments. For example, the JSON object: {"a": 1, "b": {"c": null, "d": true, "e": [1, 2]}} Will be displayed like this: { "a": 1, "b": { "c": null, "d": true, "e": [ 1, 2 ] } }

Inheritance

Constructor

goog.format.JsonPrettyPrinter(delimiters)

Parameters

delimiters : goog.format.JsonPrettyPrinter.TextDelimiters
Container for the various strings to use to delimit objects, arrays, newlines, and other pieces of the output.

Instance Methods

Public Protected Private
format(json) string
Formats a JSON object as a string, properly indented for display.
Arguments:
json : *
The object to pretty print. It could be a JSON object, a string representing a JSON object, or any other type.
Returns: string  Returns a string of the JSON object, properly indented for display.
code »
printName_(nameoutputBuffer)
Prints a property name to the output.
Arguments:
name : string
The property name.
outputBuffer : goog.string.StringBuffer
The buffer to write the response to.
code »
printObject_(valoutputBufferindent)
Formats a property value based on the type of the propery.
Arguments:
val : *
The object to format.
outputBuffer : goog.string.StringBuffer
The buffer to write the response to.
indent : number
The number of spaces to indent each line of the output.
code »
printSpaces_(indentoutputBuffer)
Print a number of space characters to the output.
Arguments:
indent : number
The number of spaces to indent the line.
outputBuffer : goog.string.StringBuffer
The buffer to write the response to.
code »
printValue_(valtypeOfoutputBuffer)
Prints a property name to the output.
Arguments:
val : string | boolean | number | null
The property value.
typeOf : string
The type of the value. Used to customize value-specific css in the display. This allows clients to distinguish between different types in css. For example, the client may define two classes: "goog-jsonprettyprinter-propertyvalue-string" and "goog-jsonprettyprinter-propertyvalue-number" to assign a different color to string and number values.
outputBuffer : goog.string.StringBuffer
The buffer to write the response to.
code »

Instance Properties

The set of characters to use as delimiters.
Code »
jsonSerializer_ : goog.json.Serializer
Used to serialize property names and values.
Code »

Package format

Package Reference