# x2js

> Transforms between XML string and JavaScript object trees.

Latest version **3.4.5** (published 2026-09-09) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install x2js
pnpm add x2js
yarn add x2js
bun add x2js
```

## Health

**Score 70/100 (B)** — status: active.

Positive: has types; no vulnerabilities; has provenance; recently updated; high maintenance score; high quality score.

Warnings: low downloads; no esm support.

## Facts

| | |
|---|---|
| Version | 3.4.5 |
| Published | 2026-09-09 |
| First published | 2015-11-03 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 53.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 100 |
| Author | Axinom |
| Maintainers | floppyfrog, axinom_kuzmin, axinomnpm, schwendner, ruwanx, x2js, dsi-hug |
| Keywords | xml, convert, transform, mapping, map |

## Links

- npm: https://www.npmjs.com/package/x2js
- Repository: https://github.com/x2js/x2js
- Homepage: https://github.com/x2js/x2js#readme
- Issues: https://github.com/x2js/x2js/issues
- npm.io page: https://npm.io/package/x2js

## Dependencies (1)

- [@xmldom/xmldom](https://npm.io/package/@xmldom/xmldom.md) ^0.9.12

## Alternatives

- [babylon](https://npm.io/package/babylon.md) — 5.1M weekly downloads
- [csscolorparser](https://npm.io/package/csscolorparser.md) — 3.7M weekly downloads
- [expr-eval-fork](https://npm.io/package/expr-eval-fork.md) — 1.5M weekly downloads
- [@leeoniya/ufuzzy](https://npm.io/package/@leeoniya/ufuzzy.md) — 247.7K weekly downloads
- [xml-parser](https://npm.io/package/xml-parser.md) — 78.4K weekly downloads

## Recent versions

- 3.4.5 (latest) — 2026-09-09
- 3.4.4 — 2022-10-24
- 3.4.3 — 2022-01-14
- 3.4.2 — 2021-09-06
- 3.4.1 — 2021-03-18
- 3.4.0 — 2019-11-26
- 3.3.1 — 2019-07-15
- 3.3.0 — 2019-05-13
- 3.2.6 — 2019-01-24
- 3.2.5 — 2019-01-23
- 3.2.4 — 2019-01-23
- 3.2.3 — 2018-11-06
- 3.2.1 — 2018-03-16
- 3.2.0 — 2018-03-16
- 3.1.1 — 2017-04-24
- … 5 more at https://npm.io/package/x2js/versions

## README

# x2js

This is a library that converts between XML and JavaScript objects.
The conversion is not necessarily lossless but it is very convenient.

[![npm version](https://badge.fury.io/js/x2js.svg)](https://badge.fury.io/js/x2js)

master | development
------ | -----------
[![CI](https://github.com/x2js/x2js/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/x2js/x2js/actions/workflows/ci.yml) | [![CI](https://github.com/x2js/x2js/actions/workflows/ci.yml/badge.svg?branch=development)](https://github.com/x2js/x2js/actions/workflows/ci.yml)

# Integration

The code is all contained within the `x2js.js` file, so you can include it directly
via a script tag. It will create `window.X2JS`, which is a constructor that can be
used to create instances of the converter, providing an optional configuration object.

In a Node app, `require("x2js")` will give you the constructor that you can use the same way.

Loading via AMD-capable loaders (e.g. require.js) is also supported and works equivalently.

The `xmldom` package is a dependency but it is only used under Node, as in browsers the browser DOM is used.

# Quick start

```js
var x2js = new X2JS();
var document = x2js.xml2js(xml);

console.log(document.MyRootElement.ElementX[1].toString());

var xml = x2js.js2xml(document);
console.log(xml);
```

See the type definitions within `x2js.d.ts` for information about what configuration options you can pass.

# Automated tests

A set of test cases are part of the project and act as the primary usage examples.
They run under Node with [Vitest](https://vitest.dev/).

Run `npm test` to execute the tests and lint the code.

# Releases

Releases are fully automated with [semantic-release](https://semantic-release.gitbook.io/semantic-release/):
every push to `master` is analyzed, and if the commits since the last release warrant one
(per the [commit message format](#commit) below), a new version is computed, `CHANGELOG.md` is
updated, a Git tag and GitHub release are created, and the package is published to npm — no manual
version bump or `npm publish` needed.

# Contributing

Contributions are welcome! To ensure speedy merges, please:

* base any pull requests on the **development** branch.
* ensure that the code passes ESLint validation with the included ruleset.

## <a name="commit"></a> Commit Message Guidelines

We want to have a comitizen friendly formatted commit messages. This leads to **more
readable messages** that are easy to follow when looking through the **project history**. But also,
we use the git commit messages to **generate the change log**.

### Commit Message Format
The commit message must respect this format that includes a **type**, a **scope** and a **subject**:

```
<type>(<scope>): <subject>
```

The **header** is mandatory and the **scope** of the header is optional.

Any line of the commit message cannot be longer 100 characters! This allows the message to be easier
to read on GitHub as well as in various git tools.

### Type
Must be one of the following:

* **feat**: A new feature
* **fix**: A bug fix
* **docs**: Documentation only changes
* **style**: Changes that do not affect the meaning of the code (white-space, formatting, missing
  semi-colons, etc)
* **refactor**: A code change that neither fixes a bug nor adds a feature
* **perf**: A code change that improves performance
* **test**: Adding missing tests or correcting existing tests
* **build**: Changes that affect the build system, CI configuration or external dependencies
            (example scopes: gulp, broccoli, npm)
* **ci**: Configuration files
* **chore**: Other changes that don't modify `src` or `test` files
* **revert**: Revert another commit
* **quiet**: Not documented in readme.md

### Scope
The scope could be anything specifying place of the commit change. For example
`DejaDatePicker`, `DejaMonacoEditor`, etc.

### Subject
The subject contains succinct description of the change:

* use the imperative, present tense: "change" not "changed" nor "changes"
* don't capitalize first letter
* no dot (.) at the end

**Breaking Changes** should start with the word `BREAKING CHANGE:` with a space or two newlines.
The rest of the commit message is then used for this.

---
_Source: https://npm.io/package/x2js · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
