diff --git a/zcl/json/parser.go b/zcl/json/parser.go index ef35985..1c3924f 100644 --- a/zcl/json/parser.go +++ b/zcl/json/parser.go @@ -19,6 +19,14 @@ func parseFileContent(buf []byte, filename string) (node, zcl.Diagnostics) { }) p := newPeeker(tokens) node, diags := parseValue(p) + if len(diags) == 0 && p.Peek().Type != tokenEOF { + diags = diags.Append(&zcl.Diagnostic{ + Severity: zcl.DiagError, + Summary: "Extraneous data after value", + Detail: "Extra characters appear after the JSON value.", + Subject: p.Peek().Range.Ptr(), + }) + } if diags.HasErrors() { // Don't return a node if there were errors during parsing. return nil, diags diff --git a/zcl/json/parser_test.go b/zcl/json/parser_test.go index a5ba789..8bb7a93 100644 --- a/zcl/json/parser_test.go +++ b/zcl/json/parser_test.go @@ -188,6 +188,11 @@ func TestParse(t *testing.T) { nil, 1, }, + { + `1 2`, + nil, + 1, + }, // Objects {