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

set object is not JSON serializable with iterable_mode=IM_ANY_ITERABLE #168

Open
gdub opened this issue Aug 22, 2022 · 6 comments
Open

set object is not JSON serializable with iterable_mode=IM_ANY_ITERABLE #168

gdub opened this issue Aug 22, 2022 · 6 comments

Comments

@gdub
Copy link

gdub commented Aug 22, 2022

>>> rapidjson.dumps({1}, iterable_mode=rapidjson.IM_ANY_ITERABLE)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: {1} is not JSON serializable
>>> rapidjson.__version__
'1.8'

Given that documentation states "any iterable will be dumped as a JSON array," I would expect a set object to serialize to an array.

Note, it does appear that creating an iterator object from the set will successfully serialize:

>>> rapidjson.dumps(iter({1}), iterable_mode=rapidjson.IM_ANY_ITERABLE)
'[1]'
@lelit
Copy link
Contributor

lelit commented Aug 23, 2022

Thank you for the report, I will try to understand and fix the issue.

@lelit
Copy link
Contributor

lelit commented Aug 23, 2022

I'm not sure if/how this should be fixed...
On one hand, I realize that IM_ANY_ITERABLE (that by the way is the default for iterable_mode) suggests that it should slurp anything for which iter(X) works, but under the hood it is actually implemented as PyIter_Check(), and thus it is currently misleading.
On the other hand, I'm reluctant to effectively rectify its implementation, because that could break existing usages: doing that for example breaks three tests, this to mention one.
I will think about this, or wait for some feedback 😜

@akhoury
Copy link

akhoury commented Nov 8, 2022

running into this issue as well

@lelit
Copy link
Contributor

lelit commented Nov 8, 2022

I started hacking on this, but got distracted away, sorry. I will try to refocus, as time permits.

@NothisIm
Copy link

NothisIm commented May 5, 2023

hi @lelit
any updates on this? would be really cool to get this fixed 🙏

@lelit
Copy link
Contributor

lelit commented May 5, 2023

No, sorry 🤦‍♂️

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

4 participants