Skip to content

Syntax error points to wrong position in json5 #47

Closed

Description

@plinnie

When there is an error in a json5 file, the error message seems to always point to the first element in the json5 file.

For example:

import json5
JSON5 = """
{  
    version: "1.0",
    author: "John Smith",
    people : [
        "Monty",
        "Python"foo
    ]    
}
"""
json5.loads(JSON5)

Gives the error:

Traceback (most recent call last):
  File "C:/Users/Admin/surfdrive/client/stuff/tests/testjson5.py", line 12, in <module>
    json5.loads(JSON5)
  File "C:\Users\Admin\Anaconda3\envs\python38\lib\site-packages\json5\lib.py", line 82, in loads
    raise ValueError(err)
ValueError: <string>:3 Unexpected "v" at column 5

I would expect the error: ValueError: <string>:7 Unexpected "f" at column 16.

json5 version: 0.9.6
OS: Windows 10
Python: 3.8.8

Activity

  1. dpranke commented on Aug 25, 2021

    @dpranke
    Owner

    Yup, that looks like a bug, I'd expect the "f" as well. I'll take a look.

  2. dpranke commented on Sep 1, 2021

    @dpranke
    Owner

    Looks like this was introduced with the fix for issue #26, which was (partially) attempting to fix a different case where the position was misreported. I'll have to figure out some way to handle both cases ...

  3. thepackrat commented on Apr 16, 2022

    @thepackrat

    +1 on this one, just cost me some sanity-questioning until I figured out what the parser error was doing.

  4. added a commit that references this issue on May 9, 2022
  5. dpranke commented on May 9, 2022

    @dpranke
    Owner

    This is fixed in beb97a9. I've just pushed v0.9.8, which contains this fix, to PyPI.

    Sorry this took so long for a fix, there were $REASONS why I wasn't on top of this, plus once I started looking at it, the bug ended up being a rather subtle problem in the generated parsing code (i.e., in the parser generator).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions