티스토리 뷰
JSON (JavaScript Object Notation)
- simplest data interchange format
- lightweight text-based structure
- easy to read
- key - value pairs
- used for serialization and transmission of data between the network and the network connection
- independent programming language and platform
1. Object to JSON
- stringify (obj)
let json = JSON.stringify(true);
console.log(json); // true
json = JSON.stringify(["apple", "banana"]);
console.log(json); // ["apple", "banana"]
const rabbit = {
name: 'tori',
color: 'white',
size: null,
birthDate: new Date(),
jump: () => {
console.log(`${name} can jump!`);
}
};
json = JSON.stringify(rabbit); // method와 symbol은 X
console.log(json); // {"name":"tori","color":"white","size":"null,
// "birthDate":"2020-05-29T13:20:22.670Z"}
json = JSON.stringify(rabbit, ['name']); // {"name":"tori"}
json = JSON.stringify(rabbit, (key, value) => {
return key === 'name' ? 'ellie' : value;
});
2. JSON to Obejct
- parse (json)
json = JSON.stringify(rabbit);
const obj = JSON.parse(json, (key, value) => {
return key === 'birthDate' ? new Date(value) : value;
});
console.log(obj);
rabbit.jump(); // can jump !
obj.jump(); // error
console.log(rabbit.birthDate.getDate); // 29
console.log(obj.birthDate.getDate()); // 29
※출처
반응형
'JavaScript & TypeScript' 카테고리의 다른 글
11. Promise (0) | 2020.11.15 |
---|---|
10. Callback (0) | 2020.11.15 |
8. Array APIs (0) | 2020.11.14 |
7. Array, API (0) | 2020.11.14 |
6. what is object (0) | 2020.11.14 |
링크
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
TAG
- js api
- 킹수빈닷컴
- 이펙티브자바 아이템60
- GCP
- 김영한 JPA
- JPA 연관관계 매핑
- Spring Security
- JS 딥다이브
- BOJ
- 드림코딩
- 이펙티브자바 스터디
- 이펙티브자바 아이템59
- js array
- HTTP 완벽가이드
- REST API
- js promise
- 집 구하기
- http
- 프로그래머스 SQL
- 모던자바스크립트
- java
- 프로그래머스
- 백준
- 가상 면접 사례로 배우는 대규모 시스템 설계 기초
- 백기선 스터디
- 패스트캠퍼스 컴퓨터공학 완주반
- 김영한 http
- 이펙티브자바
- dreamcoding
- HTTP 완벽 가이드
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함