json2hcl icon indicating copy to clipboard operation
json2hcl copied to clipboard

Parsing JSON with array as root

Open ebekker opened this issue 7 years ago • 1 comments

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

ebekker avatar May 05 '17 16:05 ebekker

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.

Acconut avatar May 10 '17 18:05 Acconut