Loading Data from a file (JSON) works on GODOT (3.5.2) but not on HMTL5 Export (itch.io)

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

Loading data from a file (JSON)

Works while running in GODOT (3.5.2) , but does not works once exported to HTML5 and published on itch.io.

I could have the data in the GD script, but would prefer to have it separately.

Here is the code.

func loadFromJson():
	var file = File.new()
	if file.open("res://user_data.json", File.READ) == OK:
		var jsonStr = file.get_as_text()
		var jsonData = JSON.parse(jsonStr)
		q_data = jsonData.result
		# q_data = jsonData
		if jsonData != null:
			# Data has been loaded successfully
			print("Failed to parse JSON data.")
		print("Failed to open file for reading.")
:bust_in_silhouette: Reply From: al1f

.json files are not a godot resource, so they won’t be exported with your project. You need to tell godot to export them explicitly. Go to Project->Export and select an export preset. Then go to the Resources tab and add *.json to the text box under

Filters to export non-resource files (comma separated, e.g: *.json, *txt)

Take a look at Exporting projects — Godot Engine (3.5) documentation in English

Thanks. I actually set the option before (*.json, *.txt)

So, I re-exported the godot project, and this time I also deleted the previous zip package file from itch.io, and re-uploaded the new one generated.

Now, It is working properly.

Thanks again.

soucpower | 2023-06-18 09:40