⚡ Sangsakala Proxy 🏠 Home
Skip to content

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

Open

Description

@gdub
>>> 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]'

Activity

  1. lelit commented on Aug 23, 2022

    @lelit
    Contributor

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

  2. lelit commented on Aug 23, 2022

    @lelit
    Contributor

    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 😜

  3. akhoury commented on Nov 8, 2022

    @akhoury

    running into this issue as well

  4. lelit commented on Nov 8, 2022

    @lelit
    Contributor

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

  5. NothisIm commented on May 5, 2023

    @NothisIm

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

  6. lelit commented on May 5, 2023

    @lelit
    Contributor

    No, sorry 🤦‍♂️

  7. lelit commented on Oct 16, 2026

    @lelit
    Contributor

    First of all, I'm sorry this is taking so long.

    I reviewed PR #246, and I'm still unsure whether that is the right move here. I'm flip/flopping between two point of views...

    1. IM_ANY_ITERABLE is too broad: should be deprecated and replaced by IM_ANY_ITERATOR, what it really means now
    2. Ok, «practicality beats purity», and sets are a rather common and important iterable to be merit a special treatment
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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions