Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
kvz committed Sep 6, 2016
1 parent d46373d commit b550818
Showing 1 changed file with 50 additions and 18 deletions.
68 changes: 50 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
# json2hcl

Convert JSON to HCL via STDIN / STDOUT.
Convert JSON to HCL and HCL to JSON via STDIN / STDOUT.

This tool is in BETA. We'll update the readme from `go run main.go` -> `json2hcl` once we're
shipping binaries for all platforms.
## Install

Check the [releases](https://github.com/kvz/json2hcl/releases) for the latest version.
Then it's just a matter of downloading the right one for you platform, extracting, making the binary
executable. Here's how it looks for 64 bits Linux:

```bash
pushd /tmp
curl -SsLo json2hcl_linux_amd64.tar.gz https://github.com/kvz/json2hcl/releases/download/v0.0.5/json2hcl_linux_amd64.tar.gz
tar zxvf json2hcl_linux_amd64.tar.gz
sudo mv json2hcl_linux_amd64/json2hcl /usr/sbin/json2hcl
sudo chmod 755 /usr/sbin/json2hcl
popd
```

## Use

Expand All @@ -28,7 +40,7 @@ $ cat fixtures/infra.tf.json
Now run it through json2hcl, and it will be converted to HCL

```bash
$ cat fixtures/infra.tf.json | go run main.go
$ cat fixtures/infra.tf.json | json2hcl
"output" "arn" {
"value" "${aws_dynamodb_table.basic-dynamodb-table.arn}"
}
Expand All @@ -42,15 +54,15 @@ $ cat fixtures/infra.tf.json | go run main.go
Typical use would be

```bash
$ cat fixtures/infra.tf.json | go run main.go > infra.tf
$ cat fixtures/infra.tf.json | json2hcl > infra.tf
```

## hcl2json

As a bonus, the conversation the other way around is also supported via the `-reverse` flag:

```bash
cat fixtures/infra.tf | go run main.go -reverse
cat fixtures/infra.tf | json2hcl -reverse
# Writes JSON to the STDOUT
```

Expand All @@ -67,25 +79,45 @@ go get

## Why?

We're building a tool called Frey, and we like HCL. We'd like configuration previously
built in YAML or TOML to be in HCL now as well. It's easy to convert those to JSON,
and HCL is able to read JSON natively, but for readability and maintainability, we wanted to save
If you don't know HCL, read [Why HCL](https://github.com/hashicorp/hcl#why).

As for why json2hcl and hcl2json, we're building a tool called Frey that marries multiple underlying
tools. We'd like configuration previously written in YAML or TOML to now be in HCL now as well.
It's easy enough to convert the mentioned formats to JSON, and strictly speaking HCL is already
able to read JSON natively, so why the extra step?

We're doing this for readability and maintainability, we wanted to save
our infra recipes as HCL directly in our repos, instead of only having machine readable intermediate
JSON that we'd need to hack on.
JSON that we'd need to hack on. This saves time spotting problems, and makes the experience somewhat
enjoyable even.

In the off-chance you too have machine-readable JSON but are interested in converting that
to the more human-being friendly HCL format, we thought we'd share.
In the off-chance you too have machine-readable JSON and are interested in converting that
to the more human-being friendly HCL format, we thought we'd share this.

This tool uses already available HashiCorp libraries to support the conversion.
It's no rocket science, we're using already available HashiCorp libraries to support the conversion,
HashiCorp could have easily released their own tools around this, and perhaps they will, but
so far, they haven't.

## Todo
## Changelog

### Ideabox (Unplanned)

- [ ] Should we perhaps also support the conversion the other way? Just for fun?
- [ ] Tests
- [ ] Error handling
- [ ] Tasks for cross-compiling and shipping releases
- [ ] Give the README.md some love

### v0.0.6 (Unreleased)

- [ ] Tests

### v0.0.5 (2016-09-06)

- [x] Add hcl2json via the `-reverse` flag

### v0.0.4 (2016-09-05)

- [x] Add hcl2json via the `-reverse` flag
- [x] Error handling
- [x] Cross-compiling and shipping releases

## Contributors

- [Marius Kleidl](https://github.com/Acconut)
Expand Down

0 comments on commit b550818

Please sign in to comment.