godotengine / godotengine/godot-docs

Add loading a JSON file to documentation

Open
#8,644 2 comments 1 reaction 0 assignees View on GitHub
area:class reference enhancement
Dominant language
reStructuredText
Stars
5.7k
Forks
3.8k
Avg merge
1d 20h
Merged PRs (30d)
25

Description

**Your Godot version:**
Godot 4.2

**Issue description:**
I'm working on using a JSON file and wanted to figure out how to load and parse a JSON file.

Perhaps we could have a reference to [FileAccess](https://docs.godotengine.org/en/stable/classes/class_fileaccess.html) or provide an example when using a JSON file? I think some beginners would benefit from this because it is more likely we end up using a JSON file than just creating a JSON from the engine (as per the example provided in the documentation).

If we will do an example, maybe it would be something like
```gdscript
func read_json(json_path):
# Retrieve file
var file = FileAccess.open(json_path, FileAccess.READ)
var content = file.get_as_text()

# Parse JSON
var json = JSON.new()
var result = json.parse_string(content)

return result
```

It could also benefit from a C# version of the code.

**URL to the documentation page (if already existing):**
https://docs.godotengine.org/en/stable/classes/class_json.html

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.