How do I edit a JSON file using scripts?

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

Hi,

I recently picked up godot for a school project. I want it to involve saving and loading data from a JSON file to store data. So far, I’ve learned how to grab data using:

func load_json():
  var file = FileAccess.open("res://words.json", FileAccess.READ)
  var js = JSON.new()
  js.parse(file.get_as_text())
  var data = js.get_data()
  dict = data
  file.close()

However, I couldn’t find results to save additional dictionaries and change existing data in the JSON. The results I did find were mostly for outdated versions. Here is my attempt at a saving function (the purpose is to append a new dictionary to words.json):

func append_words(new_dict: Dictionary):
if (check() == false): 
	%OUTPUT.text = "no input, try again."
else:
	var new_json = {}
	load_json()
	new_json = dict["words"]
	var file = FileAccess.open("res://words.json", FileAccess.WRITE)
	var js = JSON.new()
	file.store_var(new_dict)
	file.close()

When I run the code and look in the words.json file, nothing changed. Help would be greatly appreciated and thanks in advance!