Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

...

Div
classapi-page

function.prettyPrintJSON(obj, options)

Section
Column
width70%

Convert a JSON object into a nicely spaced text string.

Code Block
javascript
javascript
bgColorwhite
borderStylenonejavascript
function.prettyPrintJSON(obj, options);

File name: FluidDebugging.js

Parameters

Span
classborderless-table

obj

(Object) The JSON object to print

options

(Object) (optional) Options configuring how the string is produced. The options will be passed on to JSON.stringify().

Return Value

Span
classborderless-table

String

A string representation of the JSON object.

Column
width5%

Column

See Also


Example

Code Block
javascript
javascript
var myObject = {
    arr1: ["foo", "bar"],
    obj1: {
        subObj1: "Foo",
        subObj2: "Bar"
    }
};
var string = fluid.prettyPrintJSON(myObject);

In this example, the results string will contain

Code Block
javascript
javascript
"{\n    arr1: [\"foo\", \"bar\"],\n    obj1: {\n        subObj1: \"Foo\",\n        subObj2: \"Bar\"\n    }\n}"

which, when output, would produce

Code Block
javascript
javascript
{
    arr1: ["foo", "bar"],
    obj1: {
        subObj1: "Foo",
        subObj2: "Bar"
    }
}