JavaScript JSON.stringify()
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 be converted (usually an object or array).
- replacer:
Optional. A function or array used to transform the result.
If replacer is a function, JSON.stringify will call it, 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 root object's key is an empty string: "".
If replacer is an array, only members with key values in the array are converted. The conversion order of members is the same as the order of keys in the array.
- space:
Optional. Adds indentation, spaces, and line breaks to the text. If space is a number, the return value text is indented at each level by the specified number of spaces. If space is greater than 10, the text is indented by 10 spaces. space can also be a non-number, such as \t.
Return value:
Returns a string containing the JSON text.
Example
Example
Try it yourself »
JavaScript JSON