Arrays as a key in JSON dictionary, JSON parse problem

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

Hello community,
I have a problem with JSON parsing

I have a dictionary that I save as a line to the file.json

func save_to_file():

   yield(get_tree().create_timer(0.5), "timeout")
   var save_game ="user://slot_1.json", File.WRITE)


Then I load it

func load_from_file():
   var save_game =

   if not save_game.file_exists("user://slot_1.json"):
	   print("File %s doesn't exist.","user://slot_1.json")
	   return"user://slot_1.json", save_game.READ)
   var text = save_game.get_as_text()

   var data = JSON.parse(text).result


   yield(get_tree().create_timer(0.5), "timeout")
   slots["slot_1"] = data
   yield(get_tree().create_timer(0.5), "timeout")


data structure looks like this:
data2save = { [[map_filename, node_name], node_data] }

real data example would be:
{ “[res://level1.tscn, player1]”:{“HP”:10,“weapon”:“sword”,“bDead”:False}}

when JSON parses the save_game.get_as_text() variable the Array key becomes String

Any idea how can I convert it back to an Array key? If you want more details ask me anytime

I remember I had a similar issue. I ended up making a custom string2array() function and saved it in a global/autoload file so I could re-use it.

Basically it took a string as a parameter, then created a new array, parsed the string and stored the parse string into the new array. Then the function returned the new array.

eod | 2020-12-09 07:54