Skip to content

using generators - missing iterencode _one_shot argument #314

Description

@mdobrzanski

The _one_shot was recently removed. Is there an another way to disable use of c_make_encoder at runtime?

The only idea I have is it to disable it globally with simplejson.encoder.c_make_encoder = None but then it's always disabled and that is not perfect either.

That option allowed to use generators and stream json output without allocating too much memory.

import types
import simplejson


def gen():
    yield 1
    yield 2
    yield 3


encoder = simplejson.JSONEncoder(iterable_as_array=True)
output = encoder.iterencode(gen(), _one_shot=False)

assert isinstance(output, types.GeneratorType)

print(''.join(output))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions