Loading topic
JSON.stringify does with ordinary data: which properties it reads, in what order, how it escapes strings, and what it produces for built-in types such as Map and `5 min readJSON.stringify turns values into text. JSON.parse turns that text back into JavaScript values. This chapter covers how parsing works, what values you get back, and the details that tend to surprise developers. Examples include JSON that arrives from an HTTP API, top-level primitives, duplicate k6 min readnull. JavaScript has many more. When you pass a value to JSON.stringify that JSON cannot represent, the method does not throw in most cases. It applies a fixed set of rules: it drops the value, replaces it with null5 min readJSON.parse accepts only strict JSON. If the text breaks the grammar anywhere, it throws a SyntaxError and returns nothing. In real programs the text usually comes from places you don't control: API responses, files, localStorage, message queues, and user input. One bad byte in that text can cr5 min readJSON.stringify works with one argument, and which values it drops or turns into null (undefined, functions, symbols, NaN). It also assumes you can tell an arrow function from a regular function, because the difference matters for this below.5 min readJSON.stringify puts everything on one line. That works for machines but is hard for people to read. The third argument, space, adds line breaks and indentation. This chapter covers which values space accepts, how they are normalized internally, what the indented output looks like, 5 min readJSON.stringify handles basic values, how it treats unsupported values such as undefined and functions, and how a replacer function works. You should also be comfortable with JavaScript classes and the this keyword.5 min readJSON.stringify flattens rich values into strings, numbers, booleans, null, arrays, and plain objects. When you parse that text back, you only get those same plain types. A Date comes back as an ISO string, and a Money instance comes back as an ordinary object. A reviver is the optional sec6 min readJSON.stringify walks an object, how a replacer function receives key and value, and how toJSON works. Here you will learn why some objects cannot be turned into JSON at all, how to detect that case, and the main ways to work around it. Each workaroun6 min readNumber, which is a 64-bit IEEE 754 double. Most of the time the two fit together without trouble. They stop fitting in two cases: an integer too large for a double, and a BigInt th6 min readJSON.stringify and JSON.parse do with ordinary values. You should also know how they treat undefined, functions, symbols, NaN, Dates, cycles, and BigInt, because all of that comes back here. You should be comfortable with object references in JavaSc6 min readJSON.parse works, how it throws SyntaxError, and how reviver functions visit each key/value pair. You should also be comfortable with prototypes and for...in loops in JavaScript.6 min read