JSON data is related to the dictionary, which uses dynamic types (the Variant type).
However, Godot recommends using Resource to record data, which brings type safety—you won’t have to struggle with the type of specific data—and saving advantages:
ResourceLoader, which the load() function depends on.
ResourceSaver, which contains a useful save(String path) method.
ResourcePreloader, which the preload() function uses.
This means you can save custom resources with ResourceSaver.save(my_resource_path), load/preload them with load(my_resource_path)/preload(my_resource_path), and directly store them in variables to use.
Use resources for organized data, JSON for flexible data, or communicate with APIs that require JSON data.
For example, game data such as player progress, saved levels, and user settings are statically organized, considering resources here will take many advantages. Likewise, sending internet requests depends on JSON, which stands for “JavaScript Object Notation”.
Here’s an example:
# Dictionary is common when dealing with JSON data
var dict := {
x: 12
y: 73
list: [
"Hello",
"to",
"JSON",
"with",
"dictionary"
]
}
# Converting example
var data_string := JSON.stringify(dict)
var my_data_again := JSON.parse_string(data_string)