Skip to content

adding [] to JSON output #3

Description

@burninmedia

Example using HCL2JSON from NPM on osx
$cat ./0-terraform.tf

terraform {
required_version = "= 0.11.11"
}

$ hcl2json ./0-terraform.tf

{
"terraform": {
"required_version": "= 0.11.11"
}
}

Here are the same file contents and the JSON output using your HCL2JSON on a Ubuntu Trusty docker container.
root@0de8e7724845:~# cat test.tf

terraform {
required_version = "= 0.11.11"
}

root@0de8e7724845:~# ./go/bin/hcl2json ./test.tf

{
"terraform": [
{
"required_version": "= 0.11.11"
}
]
}

Notice in the first example that there are no [] around the terraform subkeys. When I pipe this output to jq -r '.terraform' it works as expected but if I filter for a subkey like '.terraform.required_version' I get this error which I believe is due to the [] output from your tool.
root@0de8e7724845:~# ./go/bin/hcl2json ./test.tf |jq -r '.terraform'

[
{
"required_version": "= 0.11.11"
}
]

root@0de8e7724845:~# ./go/bin/hcl2json ./test.tf |jq -r '.terraform.required_version'

jq:

error: Cannot index array with string

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions