JSON.parse() => 역직렬화
JSON.stringify() => 직렬화
Number
String
Boolean
Array
Object
null
메소드, undefined는 TypeError를 발생 시킨다.
EX )
[
{
"market" : "KRW-BTC",
"korean_name" : "비트코인",
"english_name" : "Bitcoin"
},
...
]
{
"name" : "Kim Jeong Dong"
}
[
{
"name" : "Park Jun",
"age" : 30,
},
{
"name" : "Kim Mari",
"age" : 28,
}
]
OR
[
{
"habbyPrefer" : [ {"scoccer" : "상"}, {"game" : "중"} ]
}
]
const fs = require("fs");
const path = require("path");
const json = fs.readFileSync(path.join("a.json"));
const parse = JSON.parse(json);
console.log(parse);
// [ { name: 'Park Jun', age: 30 }, { name: 'Kim Mari', age: 28 } ]
const fs = require("fs");
const path = require("path");
const json = fs.readFileSync(path.join("a.json"));
const parse = JSON.parse(json);
const deSerialization = JSON.stringify(parse);
console.log(deSerialization);
// [{"name":"Park Jun","age":30},{"name":"Kim Mari","age":28}]
const fs = require("fs");
const path = require("path");
const json = fs.readFileSync(path.join("a.json"));
const parse = JSON.parse(json);
console.log(parse[0].name);
// Park Jun
<?xml version="1.0" encoding="UTF-8"?>
<GirlGroup>
<SONG like ="1">
<name>엔믹스</name>
<song>영덤 스튜핏</song>
</SONG>
<SONG like ="2">
<name>트와이스</name>
<song>우아하게</song>
</SONG>
</GirlGroup>
const fs = require("fs");
const path = require("path");
const xmlParser = require("xml2json");
let xmlFile = fs.readFileSync(path.join("a.xml"));
xmlFile = xmlParser.toJson(xmlFile);
console.log(xmlFile);
// {"GirlGroup":{"SONG":[{"like":"1","name":"엔믹스","song":"영덤 스튜핏"},
{"like":"2","name":"트와이스","song":"우아하게"}]}}
const result = JSON.parse(xmlFile);
console.log(result);
// { GirlGroup: { SONG: [ [Object], [Object] ] } }