JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 9
  • Score
    100M100P100Q26697F
  • License MIT

C++ addon to convert xml files to json files or json sting

Package Exports

  • fast-xml2json

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (fast-xml2json) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Node Module that converts XML to JSON using C++

Package support all version of node.js v0.10., v0.12. , v4.* , v5., v6.

Install

Install fast-xml2json package


    npm install --save fast-xml2json

Use Async Convertor xml files to json files

var xml2json = require('xml2json');

xml2json.convertFile(xmlFilePath, jsonFilePath, callback);

Example to use with package async

The source of package async is available for download from GitHub.

var xml2json = require('fast-xml2json');
var async = require('async');
var fs = require('fs');
var path = require('path');
var xmlFilesPath = './xmlFiles',
    jsonFilesPath = './jsonFiles',
    count = 0,
    filesArr;

filesArr = fs.readdirSync(xmlFilesPath);
if(filesArr.length > 0) {
    if(!fs.existsSync(jsonFilesPath)) fs.mkdirSync(jsonFilesPath);
    
    async.eachSeries(filesArr, function (xmlFile, callback) {
        if(path.extname(xmlFile) != '.xml' ) return callback();
        
        fileJson = path.join(jsonFilesPath, path.basename(xmlFile, '.xml') + '.json');
        xmlFile = path.join(xmlFilesPath, xmlFile);
        
        xml2json.convertFile(xmlFile, fileJson, function (err) {
            console.log(++count + ': ' + fileJson);
            callback();
        });
    }, function (err) {
        // do something
    });
} else {
    console.log('Directory ' + xmlFilesPath + ' doesn\'t have xml files' );
}