JSON.stringify()

Converts a JavaScript value to a JSON string.

Syntax

javascript
JSON.stringify(value, replacer, space)

Example

javascript
const obj = { name: "Alice", age: 28 };
const json = JSON.stringify(obj, null, 2);
console.log(json);