Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3
Include Page
sneak peek warning
sneak peek warning
{div:class=} h1.
Wiki Markup
Div
classapi-page

function.prettyPrintJSON(obj,

options)

{section} {column:width=70%} Convert a JSON object into a nicely spaced text string. {code:javascript|borderStyle=none|bgColor=white}

Section
Column
width70%

Convert a JSON object into a nicely spaced text string.

Code Block
javascript
javascript
bgColorwhite
borderStylenone

function.prettyPrintJSON(obj, options);
{code} *File

File name:

* {{

FluidDebugging.js

}} h2. Parameters {span:class=

Parameters

Span
classborderless-table

} |*{{obj}}*|

obj

(Object)

The

JSON

object

to

print | |*{{options}}*|

print

options

(Object)

(optional)

Options

configuring

how

the

string

is

produced.

The

options

will

be

passed

on

to

{{

JSON.stringify()

}}. | {span} h2. Return Value {span:class=borderless-table} |*String*| A string representation of the JSON object. | {span} {column} {column:width=5%} {column} {column} h3. See Also * [fluid.log] {column} {section} ---- h3. Example {code:javascript}

.

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);
{code}

In

this

example,

the

results

{{

string

}}

will

contain

{code:javascript}

Code Block
javascript
javascript

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

which,

when

output,

would

produce

{code:javascript}

Code Block
javascript
javascript

{
    arr1: ["foo", "bar"],
    obj1: {
        subObj1: "Foo",
        subObj2: "Bar"
    }
}{code} {div
}