HCL to JSON util?

1,012 views
Skip to first unread message

Russell Roy

unread,
Oct 7, 2014, 8:58:25 PM10/7/14
to terrafo...@googlegroups.com
Does anyone have an HCL to JSON utility?

Mitchell Hashimoto

unread,
Oct 7, 2014, 9:05:07 PM10/7/14
to Russell Roy, <terraform-tool@googlegroups.com>
Russell,

There isn't one currently, but this shouldn't be too hard to build
(for the endeavoring fellow). Using this lib:
https://github.com/hashicorp/hcl

Should be able to decode into `interface{}` and then just re-encode
with JSON using built-in Go.

That might work.

Best,
Mitchell

On Tue, Oct 7, 2014 at 5:58 PM, Russell Roy <russ...@gmail.com> wrote:
> Does anyone have an HCL to JSON utility?
>
> --
> You received this message because you are subscribed to the Google Groups "Terraform" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to terraform-too...@googlegroups.com.
> To post to this group, send email to terrafo...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/terraform-tool/18ea90f4-89fd-4c1a-8949-fa911db7c258%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Kevin van Zonneveld

unread,
Sep 6, 2016, 6:21:24 AM9/6/16
to Terraform


On Wednesday, October 8, 2014 at 2:58:25 AM UTC+2, Russell Roy wrote:
Does anyone have an HCL to JSON utility?

Hey there, you can use the HCL printer (and `terraform fmt`) to do this now. Marius Kleidl and I took the liberty of wrapping a few of HashiCorp's libraries and release `json2hcl` (and hcl2json via `-reverse`) binaries for this. In the off chance this is still useful: https://github.com/kvz/json2hcl 

kjetil....@gmail.com

unread,
May 2, 2018, 5:29:15 AM5/2/18
to Terraform
i cannot convert a tf to json and back again .. ( json2hcl -revers < a.tf | json2hcl > b.tf )



"terraform" = {
  "backend" "local" {
    "key" = "x.tfstate"
  }
}
 
-- result b.tf

"terraform" = {
  "backend" = {
    "local" = {
      "key" = "x.tfstate"
    }
  }
}



once back as b.tf iIT IS NOT valid syntax

regards
Reply all
Reply to author
Forward
0 new messages