🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

json2xml

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json2xml

Simple JavaScript Object to XML string converter.

0.1.3
latest
Source
npm
Version published
Weekly downloads
32K
-14.71%
Maintainers
1
Weekly downloads
 
Created
Source

node-json2xml

Description

Simple JavaScript Object to XML string converter.

Installation

Install via npm, which will download json2xml and all of its dependencies.

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.

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

// 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>'

FAQs

Package last updated on 14 Nov 2016

Did you know?

Socket

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.

Install

Related posts