# JavaScript JSON.stringify()
[ JavaScript JSON](#)
* * *
The JSON.stringify() method is used to convert a JavaScript value to a JSON string.
### Syntax
JSON.stringify(value[, replacer[, space]])
**Parameter Description:**
* **value:**
Required. The JavaScript value to convert (usually an object or array).
* **replacer:**
Optional. A function or array used to transform the result.
If the replacer is a function, JSON.stringify will call this function, passing in the key and value of each member. The return value is used instead of the original value. If this function returns undefined, the member is excluded. The key of the root object is an empty string: "".
If the replacer is an array, only members with keys present in the array are converted. The order of conversion is the same as the order of keys in the array.
* **space:**
Optional. Text to add indentation, spaces, and line breaks. If space is a number, the returned text is indented by that many spaces per level. If space is greater than 10, the text is indented by 10 spaces. space can also be a non-numeric value, such as: t.
### Return Value:
Returns a string containing the JSON text.
### Example
### Example
var str = {"name":"", "site":""}str_pretty1 = JSON.stringify(str)document.write("Single parameter case:"); document.write("
"); document.write("
" + str_pretty1 + "
"); document.write("
"); str_pretty2 = JSON.stringify(str, null, 4)//Indent the document with four spaces.write("Case with parameters:"); document.write("
"); document.write("
" + str_pretty2 + "
"); // pre Used for formatted output
[Try it Β»](#)
[ JavaScript JSON](#)