Any recommendation for xml to json for Node.js?

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.


Chekout http://hemanth.github.com/node-rsj/


Where do you see that xml2js is deprecated? It has recent activity (as of March 2013) and has worked great with node 0.8.

I use it and am happy with it!


libxmljs and node-o3-xml are great and fast, but beware that they both need to compile binary components. And if you are using them for a module that will be used by others, that caveat is even more serious.

Taking a higher-level view for a moment, remember that node is single-threaded. So, any XML parsing you do is going to block the node process. To me, that means that XML parsing should never be performed in the same process as your main app. Then, once you move XML parsing to a separate process, maybe a little speed can be sacrificed in favor of ease of installation and greater portability.

Personally, that's why I use sax.js -- a pure JavaScript SAX parser -- in my feedparser library (if you're parsing RSS/Atom/RDF feeds, please consider trying it -- comments and pull requests are more than welcome). And honestly, when parsing something as big as an RSS feed, there is no discernable speed difference between sax.js and libxmljs. If you're parsing enormous XML files, you may notice a difference, I suppose. But even then, one nice thing about sax.js is the streaming. Unlike libxmljs (last I used it), you can pipe a stream into sax.js rather than having to read the entire XML document into memory. If you're parsing enormous files, you will love that!

Tags:

Xml

Json

Node.Js