티스토리 뷰
JSON은 "JavaScript Object Notation"의 약자로, 데이터 교환을 위해 사용되는 경량의 데이터 형식입니다.
JSON.stringify(value[, replacer[, space]])
const person = {
name: "John",
age: 30,
city: "New York"
};
const jsonString = JSON.stringify(person);
console.log(jsonString);
{"name":"John","age":30,"city":"New York"}
// replacer 옵션과 space 옵션 사용 예제
const person = {
name: "John",
age: 30,
city: "New York",
sensitiveInfo: "This should be hidden"
};
// replacer 함수를 사용하여 sensitiveInfo 속성을 필터링하고 변환
const filteredJSON = JSON.stringify(person, (key, value) => {
if (key === "sensitiveInfo") {
return undefined; // 해당 속성은 무시됨
}
return value;
}, 2); // 2개의 공백 문자로 들여쓰기
console.log("Filtered JSON:");
console.log(filteredJSON);
// space 옵션을 사용하여 가독성을 높인 JSON 문자열 생성
const formattedJSON = JSON.stringify(person, null, 4); // 4개의 공백 문자로 들여쓰기
console.log("\nFormatted JSON:");
console.log(formattedJSON);
Filtered JSON:
{
"name": "John",
"age": 30,
"city": "New York"
}
Formatted JSON:
{
"name": "John",
"age": 30,
"city": "New York",
"sensitiveInfo": "This should be hidden"
}
반응형
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
TAG
- 아이폰
- 문자 자르기
- mssql
- nl2br
- System.Diagnostics
- html tag
- await
- 상품 등록
- App Store
- 앱 스토어
- 제품 등록
- MainActor
- 명령어
- async
- trim
- Task
- 진수 변환
- hyper-v
- 특정 문자를 기준으로 자르기
- system.io
- FileUpload
- In App Purchase
- .submit()
- 공백제거
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함