JSON.parse
JSON
library to handle JSON, not unlike the Math
library that we've used in Basics. In the following example, we show how a string containing JSON (e.g. one that might be read from a JSON file) can be converted to a JS Object with the built-in JSON.parse
method. Once converted, we can access the JSON data using regular JS Object syntax. If the outer-most data structure in the JSON string were an array, JSON.parse
would return an array data structure instead.JSON.stringify
parse
is stringify
. stringify
takes an array or JS Object and turns it into a JSON string. This is useful for saving data to disk, because there is no way to directly write an array or JS Object to a file without first converting it to string format.parse
and stringify
methods in the Chrome DevTools console. Verify they do what you expect.