Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

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.

License

NotificationsYou must be signed in to change notification settings

kvz/json2hcl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

59 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 thereleases for the latest version.Then it's just a matter of downloading the right one for you platform, and making the binaryexecutable.

Linux

Here's how it could look for 64 bits Linux, if you wantedjson2hcl 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 wantedjson2hcl 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 examplefixtures/infra.tf.json beingconverted 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/kvzcd~/go/src/github.com/kvzgit clone git@github.com:kvz/json2hcl.gitcd json2hclgo get

Why?

If you don't know HCL, readWhy HCL.

As for why json2hcl and hcl2json, we're building a tool called Frey that marries multiple underlyingtools. 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 alreadyable to read JSON natively, so why the extra step?

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

In the off-chance you too have machine-readable JSON and are interested in converting thatto 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, butso 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

About

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.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp