• Stars
    star
    504
  • Rank 87,537 (Top 2 %)
  • Language HCL
  • License
    MIT License
  • Created about 8 years ago
  • Updated 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Convert JSON to HCL, and vice versa. We don't use json2hcl anymore ourselves, so we can't invest time into it. However, we're still welcoming PRs.

Build Status

json2hcl (and hcl2json)

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

Warning

We don't use json2hcl anymore ourselves, so we can't invest time into it. However, we're still welcoming PRs.

Install

Check the releases for the latest version. Then it's just a matter of downloading the right one for you platform, and making the binary executable.

Linux

Here's how it could look for 64 bits Linux, if you wanted json2hcl available globally inside /usr/local/bin:

curl -SsL https://github.com/kvz/json2hcl/releases/download/v0.0.6/json2hcl_v0.0.6_linux_amd64 \
  | sudo tee /usr/local/bin/json2hcl > /dev/null && sudo chmod 755 /usr/local/bin/json2hcl && json2hcl -version

OSX

Here's how it could look for 64 bits Darwin, if you wanted json2hcl available globally inside /usr/local/bin:

curl -SsL https://github.com/kvz/json2hcl/releases/download/v0.0.6/json2hcl_v0.0.6_darwin_amd64 \
  | sudo tee /usr/local/bin/json2hcl > /dev/null && sudo chmod 755 /usr/local/bin/json2hcl && json2hcl -version

Use

Here's an example fixtures/infra.tf.json being converted to HCL:

$ json2hcl < fixtures/infra.tf.json
"output" "arn" {
  "value" = "${aws_dynamodb_table.basic-dynamodb-table.arn}"
}
... rest of HCL truncated

Typical use would be

$ json2hcl < fixtures/infra.tf.json > fixtures/infra.tf

hcl2json

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

$ json2hcl -reverse < fixtures/infra.tf
{
  "output": [
    {
      "arn": [
        {
          "value": "${aws_dynamodb_table.basic-dynamodb-table.arn}"
        }
      ]
    }, 
  ... rest of JSON truncated
  ]
}

Development

mkdir -p ~/go/src/github.com/kvz
cd ~/go/src/github.com/kvz
git clone [email protected]:kvz/json2hcl.git
cd json2hcl
go get

Why?

If you don't know HCL, read Why HCL.

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. This saves time spotting problems, and makes the experience somewhat enjoyable even.

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.

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.

Changelog

Ideabox (Unplanned)

  • Give the README.md some love

v0.0.7 (Unreleased)

  • Tests

v0.0.6 (2016-09-06)

  • Deprecate goxc in favor of native builds

v0.0.5 (2016-09-06)

  • Add hcl2json via the -reverse flag

v0.0.4 (2016-09-05)

  • Error handling
  • Cross-compiling and shipping releases

Contributors

More Repositories

1

bash3boilerplate

Templates to write better Bash scripts
Shell
2,092
star
2

cronlock

cronlock lets you deploy cronjobs cluster-wide without worrying about overlaps. It uses Redis to keep track of locks.
Shell
268
star
3

system_daemon

Discontinued. All the boilerplate required to daemonize php
PHP
143
star
4

nsfailover

Let's Make DNS Outage Suck Less
Shell
102
star
5

ochtra

One Commit Hook To Rule All
Shell
85
star
6

invig

🌿 Invig automatically converts ES5 & CoffeeScript codebases to ES6 with Aligned JavaScript Standard Style
JavaScript
62
star
7

metriks

[UNMAINTAINED] A lightweight server graphing framework
JavaScript
56
star
8

cakephp-elasticsearch-plugin

Discontinued. CakePHP plugin for Elasticsearch: the Open Source, Distributed, RESTful, Search Engine
PHP
45
star
9

logstreamer

Prefixes streams (e.g. stdout or stderr) in Go
Go
45
star
10

fakefile

The Universal Makefile for JavaScript
JavaScript
41
star
11

lanyon

Deprecated
JavaScript
35
star
12

eventcache

Discontinued. PHP caching & invalidation for the lazy coder
PHP
15
star
13

airbud

Retrieving stuff from the web is unreliable. Airbud adds retries for production, and fixture support for test.
CoffeeScript
15
star
14

environmental

Node project that aims to provide code and conventions to deal with environment vars for configuration in a structured, reusable, pleasant way
JavaScript
13
star
15

packing-list

An MIT Licensed packing list for short trips abroad
12
star
16

deprecated

My deprecated repositories are now separate branches in this repository
12
star
17

on-the-githubs

Aggregates GitHub community activity as seen on http://tus.io and http://uppy.io .
JavaScript
11
star
18

rotation

Generate filenames suitable for backup rotation
JavaScript
9
star
19

node-depurar

Node.js debugging for the truly lazy
CoffeeScript
7
star
20

youtube-id

PHP
5
star
21

ec2-instances-list

Compare all EC2 instances in one sortable table
CSS
5
star
22

baseamp

Convert your Markdown todo lists to Basecamp Todolists and back
CoffeeScript
4
star
23

scrolex

Execute commands, scroll back the stdout & stderr, prefix by user-defined categories
JavaScript
4
star
24

riak-formation

Create/restore a riak cluster on any cloudprovider using Terraform
Shell
3
star
25

cakephp-ipv6-plugin

Discontinued. Plugin-wrapped CakePHP behavior to work with IPv6 addresses with efficient MySQL storage
PHP
3
star
26

huemidoro

Turns all your Philips HUE lamps red when it's time for a break :)
CoffeeScript
3
star
27

ratestate

A ratelimiter that can transmit states of different entities while avoiding transmitting the same state twice, and adhering to a global speed limit.
CoffeeScript
3
star
28

dialout

☎️➡️
JavaScript
2
star
29

x264

C
1
star
30

sledge

🔨
CoffeeScript
1
star
31

jekyll-fix-titlecase

Fixes title casing in markdown blogposts. Uppercases all words except for code, abbreviations, 'and', 'the', 'a', etc.
JavaScript
1
star