Skip to content

Allow to disable internal string key caching for json.loads() #131955

@nineteendo

Description

@nineteendo

Feature or enhancement

Proposal:

Could we add an option to disable key caching like I added in jsonyx 2.2? Or should we tell people to use my library instead? We already have the option to disable checking for circular references in json.dumps() which is much more dangerous.

>>> b"abc".decode() is not "abc" # "abc" is not interned
True
>>> dcts = json.loads('[{"abc": 1}, {"abc": 2}, {"abc": 3}]')
>>> len({id(key) for dct in dcts for key in dct})
1
>>> dcts = json.loads('[{"abc": 1}, {"abc": 2}, {"abc": 3}]', cache_keys=False)
>>> len({id(key) for dct in dcts for key in dct})
3

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

No response

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    performancePerformance or resource usagestdlibStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancement

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions