Skip to content

json mishandles integers in keys of dictionaries #91774

Closed
@eebop

Description

@eebop

Bug report

When json encounters a integer as a key of a dictionaries, it converts it to the string representation of that int, which can cause problems.

import json
a = json.dumps({1:'a'})
b = json.loads(a)
b
{'1': 'a'}
b[1]
Traceback (most recent call last):
File "", line 1, in
KeyError: 1

Your environment

  • CPython versions tested on:
    python 3.10.4

  • Operating system and architecture:
    ubuntu x86-64
    GCC 9.4.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-featureA feature request or enhancement

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions