【My Study Note】JS JSON
Basics

JSON characteristics
- String properties must be surrounded in double quotes.
- JSON strings cannot hold functions
- Valid JSON doesn’t allow the use of JavaScript comments
- Objects have double-quoted strings for all keys
- When you stringfy a JavaScript object containing a method, that method will be excluded from the stringfy operation
Codes
JSON.parse()
const obj = JSON.parse('{"name":"John", "age":30, "city":"New York"}');
A common use of JSON is to exchange data to/from a web server. When receiving data from a web server, the data is always a string. Parse the data with JSON.parse(), and the data becomes a JavaScript object.
» More about this code
JSON.stringify()
const myJSON = JSON.stringify(obj);
A common use of JSON is to exchange data to/from a web server. When sending data to a web server, the data has to be a string. Convert a JavaScript object into a string with JSON.stringify().
» More about this code