Creating a new json file rather than just saving to one.

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By stubbsy345
:warning: Old Version Published before Godot 3 was released.

Hi, so what I want to do is create a new JSON file out of some content that the user puts in themselves. I would like to save this to a new JSON file when this happens. Is there a way of creating a new file, or must it always save to a preexisting file?

:bust_in_silhouette: Reply From: Zylann

When you save a file in Godot using the WRITE flag, if the file doesn’t exist, it will be created. If it already exist, it will be replaced: http://docs.godotengine.org/en/stable/classes/class_file.html#numeric-constants

var file = File.new()
file.open("user://save.json", File.WRITE)
file.store_string(json_text)
file.close()