xml-to-sorted-json
v1.0.3
Published
π A simple CLI tool that converts XML to JSON and **sorts the properties alphabetically** for deterministic comparison.
Readme
xml-to-sorted-json
π A simple CLI tool that converts XML to JSON and sorts the properties alphabetically for deterministic comparison.
Features
β
Converts XML to JSON
β
Sorts object keys alphabetically
β
Works with nested structures
β
Automatic output file naming (if no output file is specified)
β
Easy-to-use CLI
π₯ Installation
Global Install (Recommended)
npm install -g xml-to-sorted-jsonLocal Install (for project usage)
npm install --save-dev xml-to-sorted-jsonπ Usage
Basic CLI Usage
xml-to-sorted-json <input.xml> [output.json]Examples
1οΈβ£ Convert XML to JSON (Automatic Output Name)
xml-to-sorted-json myfile.xmlβ
This will create myfile.json in the same directory.
2οΈβ£ Convert XML to JSON (Custom Output Name)
xml-to-sorted-json input.xml output.jsonβ
This will save the sorted JSON as output.json.
3οΈβ£ Prevents Overwriting the Input File
xml-to-sorted-json myfile.xml myfile.xmlβ Error: Prevents overwriting myfile.xml with JSON.
Example Input (input.xml)
<root>
<b>2</b>
<a>
<z>9</z>
<y>8</y>
</a>
<c>
<d>4</d>
<a>1</a>
</c>
</root>Example Output (input.json)
{
"root": {
"a": {
"y": 8,
"z": 9
},
"b": 2,
"c": {
"a": 1,
"d": 4
}
}
}π Development
Clone the Repository
git clone https://github.com/yourusername/xml-to-sorted-json.git
cd xml-to-sorted-jsonInstall Dependencies
npm installBuild the Project
npm run buildRun Locally
node dist/index.js input.xml output.jsonπ Contributing
- Fork the repo
- Create a new branch (
feature/your-feature) - Commit your changes
- Push to your fork
- Create a Pull Request
π License
This project is licensed under the MIT License. See the LICENSE file for details.
π Like this project? Give it a star! β
