xml-to-json-cli
v1.0.0
Published
Convert XML to JSON and JSON to XML from the terminal
Maintainers
Readme
xml-to-json-cli
Convert XML to JSON and JSON to XML from the terminal.
Installation
npm install -g xml-to-json-cliUsage
XML to JSON
# From file
xml-to-json-cli input.xml
# From stdin
cat input.xml | xml-to-json-cli
# Save to file
xml-to-json-cli input.xml -o output.jsonJSON to XML
# From file
xml-to-json-cli input.json --reverse
# From stdin
cat input.json | xml-to-json-cli --reverse
# Save to file
xml-to-json-cli input.json --reverse -o output.xmlOptions
| Flag | Description |
|------|-------------|
| --reverse, -r | Convert JSON to XML instead of XML to JSON |
| --output, -o | Write output to a file |
| --compact, -c | Minified output (no indentation) |
| --indent <n> | Indentation spaces (default: 2) |
| --version, -V | Show version |
| --help, -h | Show help |
Features
- XML to JSON and JSON to XML conversion
- Read from file or stdin
- Pretty-print with configurable indentation
- Compact/minified output mode
- Preserves XML attributes with
@_prefix - Handles CDATA sections
- Supports XML namespaces
- Validates XML before converting
Examples
Pretty-print with 4-space indent:
xml-to-json-cli data.xml --indent 4Compact JSON output:
xml-to-json-cli data.xml --compactPipe from curl:
curl -s https://example.com/feed.xml | xml-to-json-cliRound-trip conversion:
xml-to-json-cli input.xml | xml-to-json-cli --reverseLicense
MIT
