When using the stringify method with a Dictionary with integer as keys, keys are converted to String

Godot Version

4.6.1.stable

Question

While extending my save/load mechanism, I encountered a weird situation. I am trying to save a list of Dictionary, each of them having one of the record being a nested Dictionary. In this nested Dictionary, the values are themselves a Dictionary, with keys and values as integer.

Here is how the data would look like:

dict:Dictionary = {
&"filename": "res://locations/house.tscn",
&"history": {%"item1": {1:10}, %"item2": {1:20}},
}

I am saving my data using the JSON methods. Here is the code I am using:

var save_file = FileAccess.open(location_save_path, FileAccess.WRITE)
	for dict:Dictionary in locations_data:
		var json_string = JSON.stringify(dict)
		save_file.store_line(json_string)

When doing so, the value of json_string becomes:

{"history":{"item1":{"1":10},"item2":{"1":20}},"filename":"res://locations/ciaran_house.tscn"}

As you can see, the Keys of the second-level Dictionary, which were integer in the original variable, are converted in String (but not the Values). This seemed like a quite random behaviour, but there might be a good explanation. Is it something I am doing in the way I try to use the Stringify method? Is it possible to avoid this conversion?

Thanks

What would you expect to happen here (i.e. how would it look/work in your expectation, realized that could come off as snarky because text and English)? The JSON conversion is nested, and JSON doesn’t support non-string keys

I guess I have my answer when you say that json doesn’t support nonstring keys.

I would have expected something lik

history":{"item1":{1:10},"item2":{1:20}}