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

Check for None key fails when using parse #122

Open
silentninja opened this issue Feb 13, 2025 · 0 comments
Open

Check for None key fails when using parse #122

silentninja opened this issue Feb 13, 2025 · 0 comments

Comments

@silentninja
Copy link

Issue Description

When using simdjson.Parser.parse, checking if a None key exists in the parsed object results in a TypeError: expected bytes, NoneType found.

Example Code:

import simdjson
parser = simdjson.Parser()
doc = parser.parse(b'{"res": [{"name": "first"}, {"name": "second"}]}')
if not None in doc:  # This line raises the error
    pass

Error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "simdjson/csimdjson.pyx", line 316, in csimdjson.Object.__contains__
TypeError: expected bytes, NoneType found

Expected Behavior

The check should return False (as it does with simdjson.loads), since None is not a valid JSON key.

Working Example with simdjson.loads:

import simdjson
doc = simdjson.loads(b'{"res": [{"name": "first"}, {"name": "second"}]}')
if not None in doc:  # Correctly returns False
    pass
@silentninja silentninja changed the title Check for None key fails Check for None key fails when using parse Feb 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant