JSON.stringify()
JSON.stringify() is a JavaScript method in the JSON category. Converts a JavaScript value to a JSON string. The syntax is JSON.stringify(value, replacer, space). A typical example: JSON.stringify({a:1, b:2}) // "{"a":1,"b":2}". Another practical use — Pretty print JSON: const obj = { name: 'Alice', hobbies: ['coding', 'music'] } console.log(JSON.stringify(obj, null, 2)) Its time complexity is O(n), which matters when it runs over large inputs. The TypeScript signature is (value: any, replacer?: any, space?: string | number): string. Common pitfall — Strips functions and undefined values. Functions, undefined, and Symbol values are omitted or converted to null in JSON.stringify(). Use a replacer function to customize. A close sibling is JSON.parse(), which parses a JSON string into a JavaScript value. More about this category: JSON methods for data serialization — stringify and parse. Related JSON methods: JSON.parse(). This page is part of the free JS Reference documentation covering 1027+ methods, each with syntax, parameters, return values, examples, and common pitfalls.