How do I convert HashiCorp Configuration Language into JSON?

Viewed 21141

In order to better understand terraform I'd like to be able to translate HCL into the equivalent JSON. I got the HCL parser (https://github.com/hashicorp/hcl) to build and the tests to run but I don't see any command to take in an HCL file and output JSON.

There's a python implementation of HCL and it includes a utility that converts HCL to JSON, but it has some rather strange/unexpected behavior, and I would like to confirm that the behavior comes from the HCL language and isn't specific to the python implementation. e.g.

> cat foo.tf 
service {
    key = "aaa"
}

service {
    key = 0x10
    foo = "bar"
}

> hcltool foo.tf 
{
    "service": [
        {
            "foo": "bar",
            "key": "aaa"
        },
        {
            "key": 16
        }
    ]
}
2 Answers
Related