SyntaxStudy
Sign Up
JavaScript Beginner 4 min read

JSON.stringify()

JSON.stringify()

JSON.stringify() converts a JavaScript value to a JSON string. It accepts optional replacer and spacing arguments for filtering and formatting.

Example
const user = { name: "Alice", age: 30, active: true };

JSON.stringify(user);
// {"name":"Alice","age":30,"active":true}

// Pretty-print with 2-space indent
JSON.stringify(user, null, 2);
// {
//   "name": "Alice",
//   "age": 30,
//   "active": true
// }

// Filter: only include specific keys
JSON.stringify(user, ["name", "age"]);
// {"name":"Alice","age":30}
Pro Tip

Functions, undefined, and Symbols are omitted by JSON.stringify — they are not valid JSON values.