Javascript 표준내장객체 (JSON)

#Javascript 기초 정리
Written by Owen2024년 9월 23일 · 1 min read

시리즈의 글 (5개)

  1. Javascript 표준내장객체 (JSON)
  2. Javascript 표준내장객체 (객체)
  3. Javascript 표준내장객체 (배열)
  4. Javascript 표준내장객체 (날짜)
  5. Javascript 표준내장객체 (문자,숫자,수학)

banner

by Kyojin Hwang


📚카테고리 (Category)

📌 JSON 이란?

  • 데이터 전달을 위한 표준 포맷
  • 문자, 숫자, 불린, Null, 객체, 배열만 사용
  • 문자는 큰 따옴표만 사용
  • 후행 쉼표 사용 불가
  • .json 확장자 사용

📌 JSON.stringify

  • 데이터를 JSON 문자로 변환한다.
  • string type
console.log(JSON.stringify('Hello World'))
console.log(JSON.stringify(3))
console.log(JSON.stringify(true))
console.log(JSON.stringify(null))
console.log(JSON.stringify({ a: 1, b: 2 }))
console.log(JSON.stringify([1, 2, 3]))
// "'Hello World'"
// "3"
// "true"
// "null"
// "{"a":1,"b":2}"
// "[1,2,3]"

📚Move


📌 JSON.parse

  • JSON 문자를 분석해 데이터로 변환한다.
  • 각 data 에 맞는 type에 맞게 JSON 해석
console.log(JSON.parse('"Hello World"'))
console.log(JSON.parse('3'))
console.log(JSON.parse('true'))
console.log(JSON.parse('null'))
console.log(JSON.parse('{ "a": 1, "b": 2 }'))
console.log(JSON.parse('[1, 2, 3]'))
// "Hello World"
// 3
// true
// null
// {"a":1,"b":2}
// [1,2,3]

📚Move