Subject: | Wrong character offset for syntax errors |
If there's a missing } at the end of the string when parsing an object, the error location points one character too early:
$ perl -MJSON::PP -e 'decode_json(qq({"foo":{"bar":42}))'
, or } expected while parsing object/hash, at character offset 16 (before "}") at -e line 1.
If the missing character is ], it gets it right:
$ perl -MJSON::PP -e 'decode_json(qq(["foo",{"bar":42}))'
, or ] expected while parsing array, at character offset 17 (before "(end of string)") at -e line 1.
But an unexpected " when parsing an array is off by one the other direction:
$ perl -MJSON::PP -e 'decode_json(qq(["foo",{"bar":42}"]))'
, or ] expected while parsing array, at character offset 18 (before "]") at -e line 1.
While an unexpected " when parsing an object is correct:
$ perl -MJSON::PP -e 'decode_json(qq({"foo":{"bar":42}"}))'
, or } expected while parsing object/hash, at character offset 17 (before ""}") at -e line 1.
These are just some of the errors I've found in a few minutes of experimentation. There may be more.