├── .gitignore ├── README.md ├── bin.js ├── package.json └── xml2json.js /.gitignore: -------------------------------------------------------------------------------- 1 | *.sublime-* 2 | node_modules 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # xml2json command 2 | 3 | Command that converts an XML input to a JSON output, using 4 | [xml-mapping](https://github.com/lindory-project/node-xml-mapping) npm 5 | module. 6 | 7 | ## Installation 8 | 9 | Use [npm](http://npmjs.org): 10 | 11 | $ npm install -g xml2json-command 12 | 13 | Or you can get the source code, then install dependency, using 14 | 15 | $ npm install -g 16 | 17 | from the source directory. 18 | 19 | ## Usage 20 | 21 | $ xml2json < input.xml > output.json 22 | 23 | ## Also 24 | 25 | * [https://github.com/lindory-project/node-xml-mapping](https://github.com/lindory-project/node-xml-mapping) 26 | * [https://github.com/buglabs/node-xml2json](https://github.com/buglabs/node-xml2json) 27 | 28 | ## License 29 | (The MIT License) 30 | 31 | Copyright 2012 François Parmentier. All rights reserved. 32 | 33 | Permission is hereby granted, free of charge, to any person obtaining a copy 34 | of this software and associated documentation files (the "Software"), to 35 | deal in the Software without restriction, including without limitation the 36 | rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 37 | sell copies of the Software, and to permit persons to whom the Software is 38 | furnished to do so, subject to the following conditions: 39 | 40 | The above copyright notice and this permission notice shall be included in 41 | all copies or substantial portions of the Software. 42 | 43 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 44 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 45 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 46 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 47 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 48 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 49 | IN THE SOFTWARE. 50 | -------------------------------------------------------------------------------- /bin.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | require('./xml2json.js'); -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "xml2json-command", 3 | "version": "0.0.3", 4 | "description": "Convert an XML input to a JSON output, using xml-mapping", 5 | "main": "xml2json.js", 6 | "bin": { 7 | "xml2json": "bin.js" 8 | }, 9 | "preferGlobal": true, 10 | "dependencies": { 11 | "xml-mapping": "1.0.x" 12 | }, 13 | "devDependencies": {}, 14 | "scripts": { 15 | "test": "echo \"Error: no test specified\" && exit 1", 16 | "postversion": "git push && git push --tags" 17 | }, 18 | "homepage": "https://github.com/Inist-CNRS/node-xml2json-command", 19 | "repository": { 20 | "type": "git", 21 | "url": "https://github.com/Inist-CNRS/node-xml2json-command.git" 22 | }, 23 | "keywords": [ 24 | "xml", 25 | "json", 26 | "xml2json" 27 | ], 28 | "author": "François Parmentier", 29 | "license": "MIT", 30 | "readmeFilename": "README.md" 31 | } 32 | -------------------------------------------------------------------------------- /xml2json.js: -------------------------------------------------------------------------------- 1 | /*jshint node:true */ 2 | "use strict"; 3 | 4 | var xm = require('xml-mapping'); 5 | 6 | process.stdin.resume(); 7 | process.stdin.setEncoding('utf8'); 8 | 9 | var xml = ''; 10 | process.stdin.on('data', function (chunk) { 11 | xml = xml + chunk; 12 | }); 13 | 14 | process.stdin.on('end', function() { 15 | var json = xm.load(xml); 16 | console.log(JSON.stringify(json, null, '\t')); 17 | }); 18 | --------------------------------------------------------------------------------