Converts a JavaScript value into a JSON-formatted string — the standard way to serialize data for storage or a network request.
JSON.stringify({ name: 'Ada', age: 30 });
// '{"name":"Ada","age":30}'
JSON.stringify({ a: 1, b: undefined, c: function(){} });
// '{"a":1}' — undefined & functions are dropped
JSON.stringify({ a: 1 }, null, 2); // pretty-printed with 2-space indent
- undefined, functions and Symbols are silently omitted from objects
- The 3rd argument controls pretty-printing indentation
- The 2nd argument (replacer) can filter or transform values