Skip to content

encoding/json/jsontext: make trailing comma error more clear #80115

Description

@dsnet

Go version

go1.27

Output of go env in your module/workspace:

n/a

What did you do?

Do this:

v := jsontext.Value(`["foo", "bar", "baz", ]`)
fmt.Println(v.Compact())

What did you see happen?

It correctly reports an error like:

jsontext: invalid character ']' at start of value within "/3" after offset 22

What did you expect to see?

However, it would be more helpful to report:

jsontext: invalid trailing ',' before ']' after offset 20

An accidental trailing comma is a common mistake in hand-modified JSON.
While the current syntactic error is correct (and actually the easiest to produce given the parsing context), it is not particularly easy for a human to diagnose the problem.

Metadata

Metadata

Assignees

No one assigned

    Labels

    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    Status
    Needs triage

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions