Skip to reading
GDScript Programming & Godot

ReadJSONFile()

Edition 0.86.4.1 HF1

0.86.4.1 Hotfix 1 edition. Earlier lessons and screenshots retain their original version context; revised references and supplements describe the newer behavior.

Download PDFView PDF page
On this page
Code example
ReadJSONFile(path: String, default_value: Variant = null) -> Variant

Read and parse a JSON file.

Returns: Parsed data or fallback.

Code example
ReadJSONFile("user://settings.json", {"music": 0.7})

Empty/invalid input and parsed JSON null select fallback. For distinguishing valid null, use a JSON parser explicitly.

WriteJSONFile()#

Code example
WriteJSONFile(path: String, value: Variant, indent: String = "\t") -> bool

Serialize and overwrite a user-data JSON file.

Returns: Boolean success.

Code example
WriteJSONFile("user://settings.json", {"music": 0.5}, "  ")

FileExists()#

Code example
FileExists(path: String) -> bool

Check whether a file exists.

Returns: Boolean.

Code example
FileExists("user://settings.json")

DirectoryExists()#

Code example
DirectoryExists(path: String) -> bool

Check whether a directory exists after path globalization.

Returns: Boolean.

Code example
DirectoryExists("user://tutorial")
Page 80 of 378Permalink
Go to page