Latest web development tutorials
×

JavaScript Tutorial

JavaScript Tutorial JavaScript Introduction JavaScript usage JavaScript Output JavaScript grammar JavaScript Statement JavaScript Notes JavaScript variable JavaScript type of data JavaScript Object JavaScript function JavaScript Scope JavaScript event JavaScript The string JavaScript Operator JavaScript Comparison JavaScript If...Else JavaScript switch JavaScript for JavaScript while JavaScript Break & Continue JavaScript typeof JavaScript Type conversion JavaScript Regular Expressions JavaScript error JavaScript debugging JavaScript Variable promotion JavaScript Strict mode JavaScript Use errors JavaScript Form validation JavaScript Keep the keyword JavaScript JSON JavaScript void JavaScript Code specification

JS function

JavaScript Function definition JavaScript Function parameter JavaScript Function call JavaScript Closure

JS HTML DOM

DOM Introduction DOM HTML DOM CSS DOM event DOM EventListener DOM element

JS Advanced Tutorial

JavaScript Object JavaScript Number JavaScript String JavaScript Date JavaScript Array JavaScript Boolean JavaScript Math JavaScript RegExp Object

JS Browser BOM

JavaScript Window JavaScript Window Screen JavaScript Window Location JavaScript Window History JavaScript Navigator JavaScript Pop-ups JavaScript Timing events JavaScript Cookies

JS Library

JavaScript Library JavaScript test jQuery JavaScript test Prototype

JS Examples

JavaScript Examples JavaScript Object instance JavaScript Browser object instance JavaScript HTML DOM Examples JavaScript to sum up

JS Reference Manual

JavaScript Object HTML DOM Object

JavaScript JSON.stringify ()

JavaScript JSON JavaScript JSON


JSON.stringify () method is used to convert JavaScript JSON string value.

grammar

JSON.stringify(value[, replacer[, space]])

Parameter Description:

  • value:

    Necessary, a valid JSON string.

  • replacer:

    Optional. Results for switching functions or arrays.

    If replacer is a function, then JSON.stringify will call the function, passing the key and value of each member. Use the return value instead of the original value. If this function returns undefined, the exclusion of members. Key root object is an empty string: "."

    If replacer is an array, the array having a key member of the only conversion. Conversion Order members and key in an array of the same order. When the value parameter is also an array, the array will be ignored replacer.

  • space:

    Optionally, add text indentation, spaces and line breaks, if space is a number, the return value of the specified number of spaces to indent text in each level, if space is greater than 10, the text is indented 10 spaces. There are non-numeric space can be used, such as: \ t.

return value:

Returns a string containing JSON text.

Examples

Examples

var str = { "name": "tutorial", "site": "http://www.w3big.com"}
str_pretty1 = JSON.stringify (str)
document.write ( "only one parameter case:");
document.write ( "<br>");
document.write ( "<pre>" + str_pretty1 + "</ pre>");

document.write ( "<br>");
str_pretty2 = JSON.stringify (str, null, 4) // use four spaces to indent
document.write ( "parameter case:");
document.write ( "<br>");
document.write ( "<pre>" + str_pretty2 + "</ pre>"); // pre formatted for output

try it"

JavaScript JSON JavaScript JSON