본문 바로가기
Javascript

13. [JavaScript] 표준 내장 객체 - JSON

by 뽀롱트옌드 2023. 8. 27.

🏃🏻‍♀️ 표준 내장 객체

[ JSON, .json ]

🗄💾 JSON (JavaScript Object Notation)

  • 문자, 숫자, 논리(불린), 객체, 배열, Null의 데이터만 사용가능하고 이 데이터들을 전달하기 위한 표준포멧(undefinde등 사용불가)
  • 문자데이터는 "" 만 사용가능
  • 객체의 마지막 속성과 값뒤에 ,(후행쉼표) 사용 불가능

- JSON.stringify(javascriptDate);

자바스트립트 데이터를 JSON포멧형식의 문자로 변환

console.log(JSON.stringify('Welcome to the world of Poppy!')); 
// "Welcome to the world of Poppy!"
console.log(JSON.stringify(123)); 
// JsonString -> 123
console.log(JSON.stringify(true)); 
// JsonString -> true
console.log(JSON.stringify(null)); 
// JsonString -> null
console.log(JSON.stringify({season: 'Summer',month: 8})); 
// {"season":"Summer","month":8}
console.log(JSON.stringify(['One', 2])); 
// JsonString -> ["One",2]

- JSON.parse('JsonData');

json데이터를 자바스크립트의 데이터형식으로 변환

//""까지 묶여 있어야 JSON의 문자데이터 형식으로 인식함
console.log(JSON.parse('"Welcome to the world of Poppy!"')); 
// JS String -> Welcome to the world of Poppy!
console.log(JSON.parse('123')); 
// JS Number -> 123
console.log(JSON.parse('true')); 
// JS Boolean -> true
console.log(JSON.parse('null')); 
// JS Null -> null
console.log(JSON.parse('{"season":"Summer","month":8}')); 
// JS Object -> {season: 'Summer', month: 8}
console.log(JSON.parse('["One",2]')); 
// JS Array -> (2) ['One', 2]

 

🎮 패스트캠퍼스
프론트엔드 웹 개발의 모든 것 초격차패키지 Online.