How to write to nested dictionary entries

Godot Version

v4.6.2.stable.mono.official [71f334935]

Question

im doing a save system,

func loadSave(filetoload) -> Dictionary:
	var save_file = FileAccess.open(filetoload, FileAccess.READ)
	var jsonDict = {}
	var json = JSON.new()
	while save_file.get_position() < save_file.get_length():
		var json_string = save_file.get_line()
		var parse_result = json.parse(json_string)
		if not parse_result == OK:
			print("JSON Parse Error: ", json.get_error_message(), " in ", json_string, " at line ", json.get_error_line())
			continue
	jsonDict["startingEntry"] = json.data
	return jsonDict 


func saveSave(argument) -> void:
	var jsonDict = loadSave("user://saves.json")
	print(jsonDict)
	if !jsonDict.has("startingEntry"):
		jsonDict[argument.name] = argument
	else:
		jsonDict.startingEntry[argument.name] = argument
	var save_file = FileAccess.open("user://saves.json", FileAccess.WRITE)
	var json_string = JSON.stringify(jsonDict)
	save_file.store_line(json_string)

i want for all things that im saving to do in that startingEntry, i am doing Dictionary.startingEntry[newvalue] = whatiwantthevaluetobe
while that does seem to sometimes work, its not working now
the check to see if it has the startingEntry does work but the moment i try to access it an error happens
Invalid assignment of property or key argument.name with value of type ‘Dictionary’ on a base object of type ‘Nil’.

argument in this scenario is a array with 8 values including one which has name

i dont know whats the issue so im asking here, sorry if its already been answered but i looked online to no avail

I recommend you check out my open source Disk Plugin. I just updated it yesterday with more a more comprehensive Readme including screen shots. Basically, you pass it a Dictionary, and it handles the JSON encoding for you, and puts it in a Dictionary itself to hold everything. Then you just have your loading code read the dictionary you care about on the node itself.

If you really want to code your own, you can use my code as a reference. It’s only 74 lines of code (without comments).

if !jsonDict.has("startingEntry"):
	jsonDict[argument.name] = argument

Shouldn’t you be adding “startingEntry” key here?