
Security News
GitHub Actions Pricing Whiplash: Self-Hosted Actions Billing Change Postponed
GitHub postponed a new billing model for self-hosted Actions after developer pushback, but moved forward with hosted runner price cuts on January 1.
fast-xml-parser
Advanced tools
Validate XML or Parse XML to JS/JSON very fast without C/C++ based libraries
Validate XML or Parse XML to JS/JSON very fast without C/C++ based libraries and no callback
You can use this library online (press try me button above), or as command from CLI, or in your website, or in npm repo.
Installation
$npm install fast-xml-parser
or using yarn
$yarn add fast-xml-parser
Usage
var fastXmlParser = require('fast-xml-parser');
var jsonObj = fastXmlParser.parse(xmlData);
// when a tag has attributes
var options = {
attrPrefix : "@_",
textNodeName : "#text",
ignoreNonTextNodeAttr : true,
ignoreTextNodeAttr : true,
ignoreNameSpace : true,
textNodeConversion : true
};
if(fastXmlParser.validate(xmlData)=== true){//optional
var jsonObj = fastXmlParser.parse(xmlData,options);
}
//Intermediate obj
var tObj = fastXmlParser.getTraversalObj(xmlData,options);
var jsonObj = fastXmlParser.convertToJson(tObj);
To use from command line
$xml2js [-ns|-a] <filename> [-o outputfile.json]
To use it on webpage
var isValid = parser.validate(xmlData);
var jsonObj = parser.parse(xmlData);
Give me a star, if you really like this project.
I decided to created this library when I couldn't find any library which can convert XML data to json without any callback and which is not based on any C/C++ library.
Libraries that I compared
Why not C/C++ based libraries? Installation of such libraries fails on some OS. You may require to install missing dependency manually.
Benchmark report

Don't forget to check the performance report on comparejs.
validator benchmark: 2000 tps
This tool doesn't check if the XML is valid or not. If the XML is not valid you may get invalid result.
Report an issue or request for a feature here
Your contribution in terms of donation, testing, bug fixes, code development etc. can help me to write fast algorithms.

Some of my other NPM pojects
xml2js is a similar npm package that provides XML to JavaScript object conversion. It includes options to customize the parsing process and supports builder options for converting back to XML. Compared to fast-xml-parser, xml2js may be slower but offers a more feature-rich API for handling complex XML structures.
xml-js is another npm package that converts XML text to a JavaScript object and vice versa. It can also convert XML to JSON and supports compact and non-compact modes. While fast-xml-parser focuses on speed, xml-js provides a more extensive set of conversion options.
libxmljs is a Node.js package that provides bindings to the libxml C library. It allows for parsing and serializing XML and includes XPath and XSLT support. It is different from fast-xml-parser in that it is a binding to a native library, which may offer performance benefits and additional XML processing features.
FAQs
Validate XML, Parse XML, Build XML without C/C++ based libraries
The npm package fast-xml-parser receives a total of 20,358,440 weekly downloads. As such, fast-xml-parser popularity was classified as popular.
We found that fast-xml-parser demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
GitHub postponed a new billing model for self-hosted Actions after developer pushback, but moved forward with hosted runner price cuts on January 1.

Research
Destructive malware is rising across open source registries, using delays and kill switches to wipe code, break builds, and disrupt CI/CD.

Security News
Socket CTO Ahmad Nassri shares practical AI coding techniques, tools, and team workflows, plus what still feels noisy and why shipping remains human-led.