'json.parse'에 해당되는 글 1건

  1. 2022.03.24 JSON 사용법, JSON.stringify, JSON.parse
반응형
// JSON
// JavaScript Object Notation

// 1. Object to JSON
// stringify(obj)

let json = JSON.stringify(true);
console.log(json);

json = JSON.stringify(['apple', 'banana']);
console.log(json);

const rabbit = {
    name: 'tori',
    color: 'white',
    size: null,
    birthDate: new Date(),
    symbol: Symbol("id"),
    jump: () => {
        console.log(`${name} can jump!`);
    },
};

json = JSON.stringify(rabbit);
console.log(json);

json = JSON.stringify(rabbit, ['name', 'color']);
console.log(json);

json = JSON.stringify(rabbit, (key, value) => {
    console.log(`key: ${key}, value: ${value}`);
    return value;
});
console.log(json);

json = JSON.stringify(rabbit, (key, value) => {
    console.log(`key: ${key}, value: ${value}`);
    return key === `name` ? 'batman' : value;
});
console.log(json);


// 2. JSON to Object
// parse(json)

console.clear();
json = JSON.stringify(rabbit);
//const obj = JSON.parse(json);
const obj = JSON.parse(json, (key, value) => {
    console.log(`key: ${key}, value: ${value}`);
    //return value;
    return key === 'birthDate' ? new Date(value) : value;
});

console.log(obj);
rabbit.jump();
//obj.jump();

console.log(rabbit.birthDate.getDate());
//console.log(obj.birthDate.getDate());
//console.log(obj.birthDate);
console.log(obj.birthDate.getDate());
 
----------------------------------------------------------------------------------------------------------
 
자바스크립트 10. JSON 개념 정리 와 활용방법 및 유용한 사이트 공유 JavaScript JSON | 프론트엔드 개발자 입문편 (JavaScript ES6)

https://youtu.be/FN_D4Ihs3LE

JSON Diff
JSON Beautifier
JSON Parser
JSON Validator

----------------------------------------------------------------------------------------------------------

JavaScript - JSON (1/4) : 소개

https://youtu.be/MDK3xB6SuQk

네? 저는 JSON이 뭔지 모르는데...

https://youtu.be/Pvo_AT8hnso

JSP에서 Ajax와 JSON 활용하기 강좌 1강 - 프로젝트 소개 및 기초 화면 구성하기 (JSP Ajax Basic Tutorial #1)

https://youtu.be/bWbyhYUkwDQ?list=PLRx0vPvlEmdD2mcWus8hakX103PwcSJe8

[코딩기초] JSON

https://youtu.be/jHML_8kdeoM

스프링부트 강좌 23강(블로그 프로젝트) - JSON 사용법

https://youtu.be/olaeVwjx3J8

반응형

'개발 및 관리 > Javascript' 카테고리의 다른 글

Javascript for문  (0) 2022.04.03
자바스크립트 기본 문법  (0) 2022.04.02
String.replaceAll, Promise.any  (0) 2022.03.22
Javascript Free Class  (0) 2022.03.22
Generator  (0) 2022.03.21