# json2xml

> Simple JavaScript Object to XML string converter.

Latest version **0.1.3** (published 2016-11-14) · 0 weekly downloads

## Install

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

## Health

**Score 18/100 (F)** — status: abandoned.

Positive: has types package; no vulnerabilities.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.3 |
| Published | 2016-11-14 |
| First published | 2011-06-09 |
| Weekly downloads | 0 |
| TypeScript types | separate (@types/json2xml) |
| Module format | CommonJS |
| Node | >= 0.6.0 |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 65 |
| Author | Etienne Lachance |
| Maintainers | estheban |

## Links

- npm: https://www.npmjs.com/package/json2xml
- Repository: https://github.com/estheban/node-json2xml
- Issues: https://github.com/estheban/node-json2xml/issues
- npm.io page: https://npm.io/package/json2xml

## Recent versions

- 0.1.3 (latest) — 2016-11-14
- 0.1.2 — 2015-06-19
- 0.1.1 — 2013-09-18
- 0.0.1 — 2011-06-09

## README

# node-json2xml

## Description

Simple JavaScript Object to XML string converter.

## Installation

Install via [npm](https://www.npmjs.com/package/json2xml), which will download `json2xml` and all of its dependencies.

```bash
npm install json2xml
```

## Simple usage

While the name of the repo is `json2xml`, it is really `pojo2xml`, since you will need to run `JSON.parse` on the JSON data prior to converting.

```js
var fs = require('fs');
var json2xml = require('json2xml');

fs.readFile('data.json', 'utf8', function read (err, data) {
  if (err) console.log(err);
  fs.writeFile('data.xml', json2xml(JSON.parse(data)));
});
```

## Options & Behaviour

```js
// none:
json2xml({ a: 1 });
//<a>1</a>

// empty node:
json2xml({ a: '' });
//<a/>

// add header:
json2xml({ a: 1 }, { header: true });
//<?xml version="1.0" encoding="UTF-8"?><a>1</a>

// add node attributes:
json2xml({ a: 1, attr: { b: 2, c: 3 } }, { attributes_key: 'attr' });
// <a b="2" c="3" >1</a>

// arrays:
json2xml([ { a: 1 }, { b: 2 } ]);
//'<a>1</a><b>2</b>

json2xml({ 'items': [ { item: 1 }, { item: 2 } ] });
//'<items><item>1</item><item>2</item></items>'
```

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