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
488 stars 99 forks source link

Parsing JSON with array as root #6

Open ebekker opened 7 years ago

ebekker commented 7 years ago

JSON input that starts with a root array is unparsable.

For example, start with input such as the JSON sample from here (the content of task-definitions/service.json).

You get the following error: unable to parse HCL: At 1:1: expected: IDENT | STRING | ASSIGN | LBRACE got: LBRACK

Acconut commented 7 years ago

Unfortunately, this seems to be a limitation of the underlying parsing library (the official one from Hashicorp). From reading the corresponding source code, it's clear that they only accept objects as the root on purpose (see https://github.com/hashicorp/hcl/blob/master/json/parser/parser.go#L47-L48). However, it may be a good idea to open an issue about that in their repository.