-
-
Notifications
You must be signed in to change notification settings - Fork 32k
Support the buffer protocol in json.loads() #74379
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
Comments
It is not possible to use buffer objects in json.loads() |
This isn't so easy. Supporting the buffer protocol can slowdown the common case -- str. Do you have concrete use case for this feature or add it just as an extension of bytes and bytearray support? |
Withdraw my note about slowing down str. |
The proposed patch doesn't work with all objects supporting the buffer protocol, for example it doesn't work with array.array('u', '\ufeff[1,2,3]'). This is easy to fix. But I'm not sure that it is worth to complicate the code for adding support of the buffer protocol. |
I am fine with any decision. close with "won't fix" is fine too |
Please re-open this. There is currently no way to decode JSON in the stdlib from a memoryview. In my case the memoryview comes from C code, copying it into a temporary bytes object just because json.loads() does not support the buffer protocol is very wasteful and has a significant performance impact for large amounts of JSON data. Tangentially, the type annotations for json.loads() dont raise an error if you pass in a memoryview into it. |
Please open an issue at https://github.com/python/typeshed if you want that fixed @kovidgoyal — typeshed deals with all the type annotations for the stdlib! |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
Linked PRs
The text was updated successfully, but these errors were encountered: