kvz / json2hcl

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.
https://github.com/kvz/json2hcl
MIT License
498 stars 100 forks source link

Wrong json output #24

Open nabouzidan-3as opened 1 year ago

nabouzidan-3as commented 1 year ago

According to README, the conversion of

"output" "arn" {
  "value" = "${aws_dynamodb_table.basic-dynamodb-table.arn}"
}

will return

{
  "output": [
    {
      "arn": [
        {
          "value": "${aws_dynamodb_table.basic-dynamodb-table.arn}"
        }
      ]
    }, 
  ... rest of JSON truncated
  ]
}

This is not correct, the return value should be

{
  "output": {
      "arn": {
          "value": "${aws_dynamodb_table.basic-dynamodb-table.arn}"
        }
    }, 
  ... rest of JSON truncated
}

An HCL object is unnecessarily converted into a tuple.

Acconut commented 1 year ago

Similar errors have been reported many times (e.g. https://github.com/kvz/json2hcl/issues/4, #10). The problem is that the official HCL parser library that we use, does not produce the same output as you input because there are multiple serialized version for a given HCL file. This comment contains two links with more details: https://github.com/kvz/json2hcl/issues/4#issuecomment-275513256