Skip to content

Add alias to json.JSONEncoder to drop-in API. #118

Closed
@charlesjhill

Description

@charlesjhill

The docs explicitly call out a Drop-in API which will "just work". This module covers json.{load,loads,dump,dumps}, where {dump,dumps} are aliased to the built-in module. I propose adding an alias to json.JSONEncoder to make the drop-in API more complete. I don't think this should be problematic as one would only use a JSONEncoder for the dump/s commands, which are already aliased.

In a current project, I have something like this:

from json import JSONEncoder
try:
  import simdjson as json
except ImportError:
  import json

class CustomEncoder(JSONEncoder):
  ...

If an alias is added, the above snippet would be:

try:
  import simdjson as json
except ImportError:
  import json

class CustomEncoder(json.JSONEncoder):
  ...

It's a rather minor tweak, but I think it would be nice for developer experience.

Cheers

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions