오수빈

parse xml to json

{
"_from": "xml-js",
"_from": "xml-js@^1.6.11",
"_id": "xml-js@1.6.11",
"_inBundle": false,
"_integrity": "sha512-7rVi2KMfwfWFl+GpPg6m80IVMWXLRjO+PxTq7V2CDhoGak0wzYzFgUY2m4XJ47OGdXd8eLE8EmwfAmdjw7lC1g==",
"_location": "/xml-js",
"_phantomChildren": {},
"_requested": {
"type": "tag",
"type": "range",
"registry": true,
"raw": "xml-js",
"raw": "xml-js@^1.6.11",
"name": "xml-js",
"escapedName": "xml-js",
"rawSpec": "",
"rawSpec": "^1.6.11",
"saveSpec": null,
"fetchSpec": "latest"
"fetchSpec": "^1.6.11"
},
"_requiredBy": [
"#USER",
......@@ -21,7 +21,7 @@
],
"_resolved": "https://registry.npmjs.org/xml-js/-/xml-js-1.6.11.tgz",
"_shasum": "927d2f6947f7f1c19a316dd8eea3614e8b18f8e9",
"_spec": "xml-js",
"_spec": "xml-js@^1.6.11",
"_where": "C:\\Users\\se051\\OneDrive\\바탕 화면\\나의 대학라이프\\오픈소스SW개발\\텀프\\animal-Info",
"author": {
"name": "Yousuf Almarzooqi",
......
var express = require('express');
var router = express.Router();
var request = require('request');
var convert = require('xml-js').parseString;
const convert = require('xml-js');
require('dotenv').config();
/* GET home page. */
......@@ -14,17 +14,20 @@ let user_longitude;
router.get('/hospital', function (req, res) {
let pet_url = `http://api.kcisa.kr/openapi/service/rest/convergence2019/getConver03?serviceKey=${ANIMAL_INFO_API_KEY}&numOfRows=10&pageNo=1&keyword=%EB%8F%99%EB%AC%BC%EB%B3%91%EC%9B%90&where=%EA%B0%95%EB%B6%81%EA%B5%AC`;
let petOption = {
url : pet_url,
method : 'GET'
};
request(pet_url, function(err, response, body){
if(err){
console.log(err)
}
console.log(body)
res.send("finish");
request(pet_url, function(err, response, body){
if(err) {
console.log(`err => ${err}`)
}
else {
if(res.statusCode == 200) {
var result = body;
console.log(`body data => ${result}`);
var xmlToJson = convert.xml2json(result, {compact: true, spaces: 4});
console.log(`xml to json => ${xmlToJson}`);
}
}
res.send("finish");
})
});
......