Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Tree: 07944ad033
Fetching contributors…

Cannot retrieve contributors at this time

29 lines (22 sloc) 1.01 KB

Simple SAX-based XML2JSON Parser.

It does not parse the following elements:

  • CDATA sections
  • Processing instructions
  • XML declarations
  • Entity declarations
  • Comments


npm install xml2json


var parser = require('xml2json');

var xml = "<foo>bar</foo>";
var json = parser.toJson(xml); //returns an string containing the json structure by default
  • if you want to get the Javascript object then you might want to invoke parser.toJson(xml, {object: true});
  • if you want a reversible json to xml then you should use parser.toJson(xml, {reversible: true});
  • if you want to override the default "$t" key name for a node's text value, specify the textNodeKey option. e.g., parser.toJson(xml, {textNodeKey: "text"})
  • if you want to prevent xml node attributes from appearing in the json, specify attributes: false. e.g., parser.toJson(xml, {attributes: false}). The default behavior is attributes: true.


Copyright 2011 BugLabs Inc. All rights reserved.

Jump to Line
Something went wrong with that request. Please try again.