Is it possible to convert parsed JSON keys from string to integers ?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By AltoWaltz

Similar to https://github.com/godotengine/godot/issues/33161

I have an issue where my dictionary integer keys get converted to strings and that causes issues down the line. Is it possible to convert those parsed JSON keys from strings to integers ?

JSON:

"Chests": {
    "chest1_1": true,
    "chest1_1_contents": {
        "1": ["Gold", 14],
        "2": ["Arrows_Ammo", 27]

JSON Lookup:

loot_dic =  DataImport.save_data["Chests"][current_chest.name+str("_contents")]

print(loot_dic) = {1:[Gold, 14], 2:[Arrows_Ammo, 27]

The problem is that keys (1,2, etc) are strings and I need them to be integers ? Can this be achieved ? Any help appreciated.

:bust_in_silhouette: Reply From: AlexTheRegent

You can store your chest content as array and during deserialization use element’s index as your int key. It will be faster compared to Dictionary + iteration over keys (that are presented as array).