GitHub
github.com › estheban › node-json2xml
GitHub - estheban/node-json2xml: A small JSON to XML parser
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(JSON.stringify(data)))); });
Starred by 66 users
Forked by 30 users
Languages JavaScript 100.0% | JavaScript 100.0%
npm
npmjs.com › package › json2xml
json2xml - npm
November 14, 2016 - 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>' none ·
» npm install json2xml
Published Nov 14, 2016
Version 0.1.3
Author Etienne Lachance
Repository https://github.com/estheban/node-json2xml
npm
npmjs.com › package › node-json2xml
node-json2xml - npm
Simple JavaScript Object to XML string converter.. Latest version: 0.1.8, last published: 6 years ago. Start using node-json2xml in your project by running `npm i node-json2xml`. There are no other projects in the npm registry using node-json2xml.
» npm install node-json2xml
Published Dec 19, 2018
Version 0.1.8
Author Galdan MOULINNEUF
Repository https://github.com/GaldanM/node-json2xml
npm
npmjs.com › package › xml2json
xml2json - npm
December 26, 2019 - Converts xml to json and vice-versa, using node-expat.. Latest version: 0.12.0, last published: 6 years ago. Start using xml2json in your project by running `npm i xml2json`. There are 623 other projects in the npm registry using xml2json.
» npm install xml2json
npm
npmjs.com › search
keywords:json2xml - npm search
A data to XML converter with a nice interface (for NodeJS).
Top answer 1 of 2
4
This would be a way to change the object back to the format expected in the library, although it assumes that all non object keys are supposed to be attributes (is that a valid assumption for your application?)
function groupChildren(obj) {
for(prop in obj) { // consider filtering for own properties (vs from prototype: for(prop of Object.keys(obj)) {
if (typeof obj[prop] === 'object') {
groupChildren(obj[prop]);
} else {
obj['$'] = obj['$'] || {};
obj['$'][prop] = obj[prop];
delete obj[prop];
}
}
return obj;
}
and then used like so:
var xml2js = require('xml2js');
var obj = {
Level1: {
attribute: 'value',
Level2: {
attribute1: '05/29/2020',
attribute2: '10',
attribute3: 'Pizza'
}
}
};
var builder = new xml2js.Builder();
var xml = builder.buildObject(groupChildren(obj));
which prints out:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Level1 attribute="value">
<Level2 attribute1="05/29/2020" attribute2="10" attribute3="Pizza"/>
</Level1>
2 of 2
-1
you can use this library :nashwaan/xml-js
Like This:
let xmlJ=require('xml-js');
let parseToJson=(xml)=>{
return new Promise(resolve => {
let convert;
convert=xmlJ.xml2json(xml,{compact:true});
resolve(convert);
});
};
CodeSandbox
codesandbox.io › examples › package › json2xml
json2xml examples - CodeSandbox
github.com/estheban/node-json2xml · github.com/estheban/node-json2xml/issues ·
Top answer 1 of 9
40
I've used xml-js - npm to get the desired result.
First of all I've installed xml-js via npm install xml-js
Then used the below code to get the output in json format
var convert = require('xml-js');
var xml = require('fs').readFileSync('./testscenario.xml', 'utf8');
var result = convert.xml2json(xml, {compact: true, spaces: 4});
console.log(result);
2 of 9
33
You can use xml2json npm for converting your xml in to json. xml2json.
Step 1:- Install package in you project
npm install xml2json
Step 2:- You can use that package and convert your xml to json
let xmlParser = require('xml2json');
let xmlString = `<?xml version="1.0" encoding="UTF-8"?>
<TestScenario>
<TestSuite name="TS_EdgeHome">
<TestCaseName name="tc_Login">dt_EdgeCaseHome,dt_EdgeCaseRoute</TestCaseName>
<TestCaseName name="tc_Logout">dt_EdgeCaseRoute</TestCaseName>
</TestSuite>
<TestSuite name="TS_EdgePanel">
<TestCaseName name="tc_AddContract">dt_EdgeCaseHome,dt_EdgeCaseSpectrum</TestCaseName>
</TestSuite>
<TestSuite name="TS_EdgeRoute">
<TestCaseName name="tc_VerifyContract">dt_EdgeCaseRoute</TestCaseName>
<TestCaseName name="tc_Payment">dt_EdgeCaseRoute</TestCaseName>
</TestSuite>
<TestSuite name="TS_EdgeSpectrum">
<TestCaseName name="tc_ClientFeedback">dt_EdgeCaseSpectrum</TestCaseName>
</TestSuite>
</TestScenario>`;
console.log('JSON output', xmlParser.toJson(xmlString));
Hope this might be helps to you.
Google Groups
groups.google.com › g › node-red › c › yAEx5k2UHJw
Replacement node for json2xml
If you look in the function node list you'll find a node called "JSON" and a node called "XML" these convert to and from
GitHub
gist.github.com › mediaupstream › 1495793
json2xml - Convert an xml2js JSON object back to XML · GitHub
json2xml - Convert an xml2js JSON object back to XML - json2xml.js
npm
npmjs.com › search
XML2JSON - npm search
Converts xml to json and vice-versa, using node-expat.
npm
npmjs.com › package › js2xmlparser
js2xmlparser - npm
September 20, 2022 - Since XML is a data-interchange format, js2xmlparser is designed primarily for JSON-type objects, arrays and primitive data types, like many of the other JavaScript to XML parsers currently available for Node.js.
» npm install js2xmlparser
Published Sep 20, 2022
Version 5.0.0
Author Michael Kourlas
npm
npmjs.com › package › xml-js
xml-js - npm
February 13, 2019 - To convert JavaScript object to XML text, use js2xml(). To convert JSON text to XML text, use json2xml().
» npm install xml-js
Published Feb 13, 2019
Version 1.6.11
Author Yousuf Almarzooqi
Repository https://github.com/nashwaan/xml-js
GitHub
github.com › buglabs › node-xml2json
GitHub - buglabs/node-xml2json: Converts XML to JSON using node-expat
January 7, 2021 - Converts XML to JSON using node-expat. Contribute to buglabs/node-xml2json development by creating an account on GitHub.
Starred by 810 users
Forked by 212 users
Languages JavaScript 100.0% | JavaScript 100.0%
Node-RED
flows.nodered.org › flow › 14a37244e0706b4f5ef1862693f5f533
Json2XML (flow) - Node-RED
json2xml (x1) tab (x1) Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option · Node-RED: Low-code programming for event-driven applications. GitHub · npm · Documentation · APIs · Flow Library ·
Npm
npm.io › package › json2xml
Json2xml NPM | npm.io
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>
Npm
npm.io › search › keyword:json2xml
Json2xml | npm.io
A data to XML converter with a nice interface (for NodeJS).