stringify <-> pause
JSON.parse(): JSON 문자열을 JavaScript 객체로 변환
const obj = { name: "홍길동", age: 25, married: false, family: { father: "홍판서", mother: "춘섬", }, hobbies: ["독서", "도술"], jobs: null, };
const str = JSON.stringify(obj);
'{"name":"홍길동","age":25,"married":false,"family":{"father":"홍판서","mother":"춘섬"},"hobbies":["독서","도술"],"jobs":null}'
const str2 = JSON.stringify(obj, null, 2);
{ "name": "홍길동", "age": 25, "married": false, "family": { "father": "홍판서", "mother": "춘섬" }, "hobbies": [ "독서", "도술" ], "jobs": null }
각 속성에 접근이 가능하다.
- obj.name
'홍길동'- obj.age
25- obj.married
false- obj.family
{father: '홍판서', mother: '춘섬'}- obj.family.mother
'춘섬'
JSON.stringify(): JavaScript 객체를 JSON 문자열로 변환
const str = `{ "name": "홍길동", "age": 25, "married": false, "family": { "father": "홍판서", "mother": "춘섬" }, "hobbies": ["독서", "도술"], "jobs": null }`;
const obj = JSON.parse(str);
{ name: "홍길동", age: 25, married: false, family: { father: "홍판서", mother: "춘섬" }, hobbies: [ "독서", "도술" ], jobs: null }