Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/engali94/XMLJson

Swift CLI tool for converting any XML to JSON format
https://github.com/engali94/XMLJson

cli json json-parser swift xml xml-parsing xmlserializer

Last synced: 8 days ago
JSON representation

Swift CLI tool for converting any XML to JSON format

Awesome Lists containing this project

README

        

# XMLJSON
A Swift command-line tool to easily convert XML format to JSON.



SPM




Twitter: @alihilal94

![demo](https://github.com/engali94/XMLJson/blob/master/assets/xmljsonDemo.gif)

### Requirements
- Good Mood

### Usage

```
$ xmljson -h
OVERVIEW: Convert XML Format to JSON Format.
USAGE: xmljson --dir [--files ...] [--output ] [--verbose] [--all]

OPTIONS:
-d, --dir Absolute path to a directory containing the xml files.
-f, --files XML files to be parsed.
-o, --output [Optinal] JSON file(s) output directory.
-v, --verbose Show extra logging for debugging purposes.
-a, --all Convert all XML files present in the specifed directory.
-h, --help Show help information.
```

First specify where the xml files are located through `--dir` argument **(Manadatory)**
Then you can specify the files to be converted in through `--files` argument you can pass as much as you want

```bash
$ xmljson -d ~/xml/files/dir - file1.xml filen.xml --verbose
```

If you want to convert all the XML files present in the directory, pass the `--dir` argument and `--all` flag only.

```bash
$ xmljson -d ~/xml/files/dir --all
```

if you would like to change the output directory pass it to `--output` .

```bash
$ xmljson -d ~/xml/files/dir -o ~/path/to/output/dir --all
```

### Sample
XML Input
```xml
?xml version="1.0" encoding="UTF-8"?>


Everyday 1
Giada De Laurentiis
2005
30.00


Learning XML
Erik T. Ray
2003
39.95

```

JSON Output
```json
[
{
"author" : "Giada De Laurentiis",
"title" : {
"lang" : "en",
"text" : "Everyday 1"
},
"year" : "2005",
"category" : "cooking",
"price" : "30.00"
},
{
"author" : "Erik T. Ray",
"title" : {
"lang" : "en",
"text" : "Learning XML"
},
"year" : "2003",
"category" : "web",
"price" : "39.95"
}
]
```
### Installation using [HomeBrew](https://brew.sh)
You can install xmljson using homebrew as follows:

```bash
$ brew tap engali94/formulae
$ brew install xmljson
```
### Installation using [Make](https://en.wikipedia.org/wiki/Make_%28software%29)
You can install xmljson using make as follows:

```bash
$ git clone https://github.com/engali94/XMLJson.git
$ cd XMLJson
$ make install
```

### Development
- `cd` into the repository
- run `swift package generate-xcodeproj`
- Run the following command to try it out:

```bash
swift run XMLJson --help
```

### License

XMLJson is released under the MIT license. See [LICENSE](https://github.com/engali94/XMLJson/blob/master/LICENSE) for more information.