Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Any recommendation for xml to json for Node.js?

Tags:

I've installed node-xml but I don't think it works the way I expect. and it doesnt' have example. any recommendation for xml-2-json (js) for node.js? I also looked at xml2js in npm but it is deprecated and people reported that it is broken with the latest node.js

by the way, i'm also using express. :)

like image 668
murvinlai Avatar asked Apr 15 '11 03:04

murvinlai


People also ask

Can any XML be converted to JSON?

To convert an XML document to JSON, follow these steps: Select the XML to JSON action from the Tools > JSON Tools menu. Choose or enter the Input URL of the XML document. Choose the path of the Output file that will contain the resulting JSON document.

Can JSON parse XML?

JSON is Unlike XML Because XML has to be parsed with an XML parser. JSON can be parsed by a standard JavaScript function.


1 Answers

There are many xml parsers.

Like libxmljs and node-o3-xml. The latter is made and used by Ajax.org so it should be stable.

As for converting XML to JSON, I would recommend creating an object structure from your xml and then manually calling JSON.stringify on it. This gives you complete control of how your xml data is turned into JSON.

You can then either save the JSON in a file/DB or serve it to a request.

like image 101
Raynos Avatar answered Oct 07 '22 20:10

Raynos