
JSON.stringify(), JSON.parse(), toJSON() 정리
·
프로그래밍 언어/JavaScript
JSON.stringify() 메서드 값이나 객체를 JSON 문자열로 변환한다. let lee = {name : "이용진", age : "24", weight : "need_Diet"}; let newLee = JSON.stringify(lee); console.log(newLee); 모든 문자열이 큰 따옴표로 둘러 싸인 JSON 형식의 문자열로 바뀐 것을 확인할 수 있다. JSON.parse() 메서드 JSON 문자열을 JavaScript 객체로 변환한다. let lee = `{"name" : "이용진", "age" : "24", "weight" : "need_Diet"}`; let newLee = JSON.parse(lee); console.log(newLee); 백틱으로 둘러 쌓인 JSON 문자열이..