I have this method where I receive an XML response from a remote server and I need to convert the XML to JSON so that Angular 2 can work with the data:
private extractData(res: Response) { let xml = res["_body"] console.log(xml); var parser = require('xml2json'); var json = parser.toJson(xml); return json }
I am trying to use this Node Module:https://www.npmjs.com/package/xml2json
Now this node module is written in javascript (NOT TypeScript) so I'm not sure if I can even use it in an Angular 2 app.
I am getting this compilation error:
ERROR in ./~/isemail/lib/index.js Module not found: Error: Can't resolve 'dns' in '/Users/user/ebayTool/node_modules/isemail/lib' @ ./~/isemail/lib/index.js 5:12-26 @ ./~/joi/lib/string.js @ ./~/joi/lib/index.js @ ./~/xml2json/lib/xml2json.js @ ./~/xml2json/lib/index.js @ ./~/xml2json/index.js @ ./src/app/hero.service.ts @ ./src/app/app.component.ts @ ./src/app/app.module.ts @ ./src/main.ts @ multi webpack-dev-server/client?http://localhost:4200/ ./src/main.ts webpack: Failed to compile.
So my question is how to convert XML to JSON in Angular 2 and how I can properly import xml2json Node Module to be used in my project?