Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IncompleteJSONError is not recognized for null and boolean values #42

Closed
harpener opened this issue Feb 24, 2021 · 4 comments
Closed

IncompleteJSONError is not recognized for null and boolean values #42

harpener opened this issue Feb 24, 2021 · 4 comments
Labels
bug Something isn't working question Further information is requested

Comments

@harpener
Copy link

harpener commented Feb 24, 2021

Hi guys,

we are using this library to be able to parse incomplete JSON, specifically its Python backend.

We noticed that sometimes it raises UnexpectedSymbol instead of IncompleteJSONError and after some investigation, we found out that the problem is that given JSON ended with incomplete null or true or false value. E.g. {"a": n. It seems that the lexer's state machine does not recognize it.

Do you think this is a valid case and if so, can it be fixed?

Thank you for your response.

@rtobar rtobar added the question Further information is requested label Feb 25, 2021
@rtobar
Copy link

rtobar commented Feb 25, 2021

@harpener if I understand correctly, your concern is that the type of exception raised by the code is not what you expected, and therefore you can't recognize the particular problem of an incomplete JSON document, right?

You are right that the python backend doesn't recognise these cases properly, so yes, this can be improved. On the other hand this is the slowest backend; the others do raise IncompleteJSONError on these cases, so you might be better off using those anyway. I will still improve the python backend to detect these cases and raise the appropriate exception.

EDIT: almost all other backends raise an IncompleteJSONError exception. The yajl backend (which is deprecated) doesn't, but it won't be repaired either.

@rtobar rtobar added the bug Something isn't working label Feb 25, 2021
rtobar added a commit that referenced this issue Feb 25, 2021
As pointed out in #42, the python backend failed to properly recognise
valid but incomplete JSON content when the incomplete bits were the
beginning of the "true", "false" or "null" tokens.

This commit adds support for recognising these cases, and adds test
cases that will ensure these cases are properly recognised by all
backends, including the python one.

Signed-off-by: Rodrigo Tobar <rtobar@icrar.org>
rtobar added a commit that referenced this issue Feb 25, 2021
As pointed out in #42, the python backend failed to properly recognise
valid but incomplete JSON content when the incomplete bits were the
beginning of the "true", "false" or "null" tokens.

This commit adds support for recognising these cases, and adds test
cases that will ensure these cases are properly recognised by all
backends, including the python one.

Signed-off-by: Rodrigo Tobar <rtobar@icrar.org>
@rtobar
Copy link

rtobar commented Feb 25, 2021

A fix for this is now on the master branch; now the python backend recognises incomplete JSON tokens like tru or nu as such and raises an IncompleteJSONError exception. A new version with this fix will be released to PyPI hopefully in the next day or so, but until then you can either install directly from GitHub or use a different backend.

@rtobar rtobar closed this as completed Feb 25, 2021
@harpener
Copy link
Author

Thanks for the fix. I haven't even been able to import any of the yajl backends on local Windows or production Linux environments, so I can't say how they behave. But the performance is not that important for now.

@rtobar
Copy link

rtobar commented Mar 2, 2021

ijson 3.1.4 is now available on PyPI

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants