컴퓨터 언어/JavaScript
[JavaScript] Json과 메서드
테크케찰
2021. 7. 30. 13:34
JavaScript Json 포맷에서 자주 쓰이는 메서드는 아래 두 개가 있습니다.
JSON.stringify // 객체 -> json
JSON.parse // json -> 객체
아래는 stringify와 parse의 활용 예시 코드입니다.
const user={
name:'Jason',
age:23,
job:'developer',
};
let data_string = JSON.stringify(user);
console.log(data_string); // {"name":"Jason","age":23,"job":"developer"}
const json = '{"result":true, "count":42}';
const obj = JSON.parse(json);
console.log(obj); // { result: true, count: 42 }