Organizational Research By

Surprising Reserch Topic

any recommendation for xml to json for node js

any recommendation for xml to json for node js  using -'xml,json,node.js'

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. :)

asked Sep 18, 2015 by ajit.chavhan
0 votes

Related Hot Questions

5 Answers

0 votes

There are many xml parsers.

Like libxmljs and node-o3-xml. The latter is made and used by 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.

answered Sep 18, 2015 by manju bhargava
0 votes

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!

answered Sep 18, 2015 by ashish singh
0 votes

sblom pointed out JsonML which might also be worth taking into consideration. Not sure about JsonML support in nodejs but there is already a jQuery plugin here:

answered Sep 18, 2015 by sanjaypal1983
0 votes

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!

answered Sep 18, 2015 by thiru
0 votes

As the other poster points out, node-xmltojs is probably the best way to go.

If you did want to use JSONML, I'm not sure why the JQuery plugin in the other answer is being upvoted: there's JSONML for node:

npm install jsonml


var fs = require('fs'),
  parse = require('jsonml').parse;

var jsonML = parse(fs.readFileSync('myfile.xml'));
answered Sep 18, 2015 by sandeep bhadauria