티스토리 뷰

JavaScript

[javascript] JSON.stringify 쉬운 설명

에스파니아 2022. 2. 15. 22:33
728x90
반응형

JSON

 

JavaScript Object Notation, 클라이언트와 서버 사이에서 사용하는 데이터 형식 

 

JSON.strigify(value[, replacer, [space]])

 

value : JSON 문자열로 변환할 값
replacer : 객체의 속성들은 선택하기 위한 함수 또는 배열 (null 일 경우, 모두 선택)
space : 공백(1~10)

 

예제

 

console.log(JSON.stringify(user));

console.log(JSON.stringify(user, function(key, value){
    if(typeof value === 'string'){
        return undefined;
    }else{
        return value;
    }
}))

console.log(JSON.stringify(user, ['name']));

console.log(JSON.stringify(user, null, 10));
출력화면

 

728x90
댓글
반응형
250x250
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
TAG
more
«   2026/01   »
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
글 보관함