Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jdockerty/yaml-to-json-go
Golang CLI tool to convert YAML to JSON, JSON to YAML, and to validate files.
https://github.com/jdockerty/yaml-to-json-go
cli converter go golang json json-to-yaml yaml yaml-to-json yamllint
Last synced: 3 months ago
JSON representation
Golang CLI tool to convert YAML to JSON, JSON to YAML, and to validate files.
- Host: GitHub
- URL: https://github.com/jdockerty/yaml-to-json-go
- Owner: jdockerty
- License: apache-2.0
- Created: 2020-10-29T22:00:38.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2022-04-03T21:39:10.000Z (almost 3 years ago)
- Last Synced: 2024-06-19T10:05:55.068Z (7 months ago)
- Topics: cli, converter, go, golang, json, json-to-yaml, yaml, yaml-to-json, yamllint
- Language: Go
- Homepage:
- Size: 62.5 KB
- Stars: 7
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# YAML to JSON
A small CLI application that lets you convert a YAML file into a JSON file or the other way around, depending on which you specify as the source.
You can also print out the result to the console, rather than specifying a target file in which to place the result.Simple validation is also supported, based on whether the file was valid enough to be parsed into the program.
The supported extensions are:
* `.yaml`
* `.yml`
* `.json`Various other useful methods are available in the `conversion` package that help when dealing with unstructured JSON or YAML. This may be useful when dealing with YAML or JSON in a programmatic sense.
go get -u github.com/jdockerty/yaml-to-json-go/conversion
Can be used to retreive the packages if you have Go installed.
## Install
If you already have Go installed, then you can simply run
```sh
go install github.com/jdockerty/yaml-to-json-go@latest
mv $(go env GOPATH)/bin/yaml-to-json-go $(go env GOPATH)/bin/yamltojson
```This installs the binary in your Go `bin` directory and renames it for easier access on the command line, feel free to alter this to whatever suits your needs, such as `y2j`.
An alternative method is to grab the binary file from the provided S3 bucket.
```
wget https://yaml-to-json-go.s3.eu-west-2.amazonaws.com/yamltojson.zip
unzip yamltojson.zip
sudo mv yamltojson /usr/local/bin
```Or, if you have already cloned the repository and are currently within that directory.
make install
## Usage
Converting YAML to JSON or JSON to YAML is simple in the CLI through the use of the `convert` sub-command.
yamltojson convert
This will read the source file and create/write to the target file specified. For example:
yamltojson convert ~/project/config/data.yaml ~/another-project/output.json
If you do not want to write or create the target file, you can simple output the conversion to the console window.
yamltojson convert --print a-nice-file.yml
A full directory can be converted with the `--directory` or `-d` flag too, although this works best when all of the containing files within the directory are of the same type, such as converting a folder full of JSON files into YAML.
yamltojson convert --directory=","
There is also simple validation on a list of files. This simply tells you whether a JSON or YAML file is valid or not.
yamltojson validate path/to/config.json path/to/another/file.yml