Install Asset
Install via Godot
To maintain one source of truth, Godot Asset Library is just a mirror of the old asset library so you can download directly on Godot via the integrated asset library browser
Quick Information
Unlike built-in JSON, in this plug-in 2 is not 2.0; it's 2, and 3.5 is 3.5
STDJson
A lightweight Godot 4 JSON utility addon that simplifies reading, writing, and handling JSON data.
STDJson provides a global autoload that allows you to:
- Parse JSON from strings.
- Parse JSON from files.
- Save JSON data into files.
- Automatically fix Godot's JSON number conversion behavior.
Features
- π Parse JSON from a file.
- π Parse JSON from a string.
- πΎ Save JSON data to a file.
- β¨ Optional pretty formatting.
- π’ Automatically converts whole-number floats into integers.
- π¦ Supports both JSON objects (
Dictionary) and JSON arrays (Array). - π Available globally through the
STDJsonautoload.
Why STDJson?
Godot's built-in JSON parser converts all JSON numbers into floating-point values.
For example, this JSON:
{
"id": 1,
"health": 100,
"speed": 2.5
}
will become:
{
"id": 1.0,
"health": 100.0,
"speed": 2.5
}
STDJson automatically converts numbers without a fractional part back into integers:
{
"id": 1,
"health": 100,
"speed": 2.5
}
Examples:
2.0 -> 2
15.0 -> 15
2.5 -> 2.5
This makes JSON data easier to work with when handling IDs, counters, levels, ports, and other integer-based values.
Installation
- Copy the addon folder into your project's
addonsdirectory.
Example:
res://addons/STDJson/
- Open:
Project β Project Settings β Plugins
Enable the STDJson plugin.
The plugin automatically creates the:
STDJson
autoload.
You can now use it anywhere in your project.
Usage
Parse JSON from a file
var data: Variant = STDJson.parse_file("user://settings.json")
if data == null:
return
Parse JSON from a string
var data: Variant = STDJson.parse_string("""
{
"player": {
"name": "Alice",
"level": 10
}
}
""")
Modify JSON data
data["player"]["level"] += 1
Save JSON data to a file
var result := STDJson.save_json_to_file(
data,
"user://settings.json"
)
if result == OK:
print("Saved successfully!")
Save without formatting
By default, JSON files are saved in a readable formatted style.
To save a compact JSON file:
STDJson.save_json_to_file(
data,
"user://settings.json",
false
)
Save an existing JSON string
var json_string := """
{
"name": "Alice",
"coins": 500
}
"""
STDJson.save_json_to_file(
json_string,
"user://save.json"
)
API Reference
parse_file(path: String) -> Variant
Reads a JSON file and converts it into a Godot value.
Returns:
DictionaryArraynullif reading or parsing fails
Example:
var save_data = STDJson.parse_file("user://save.json")
parse_string(json_string: String) -> Variant
Parses a JSON string and converts it into a Godot value.
Returns:
DictionaryArraynullif parsing fails
Example:
var data = STDJson.parse_string(json_text)
save_json_to_file(json: Variant, path: String, formatted: bool = true) -> int
Saves JSON data into a file.
Accepted input types:
DictionaryArray- JSON
String
Returns:
OKon successFAILEDon error
Example:
var error := STDJson.save_json_to_file(
data,
"user://save.json"
)
Complete Example
func _ready() -> void:
var player_data: Variant = STDJson.parse_file(
"user://player.json"
)
if player_data == null:
return
player_data["coins"] += 100
player_data["level"] += 1
var result := STDJson.save_json_to_file(
player_data,
"user://player.json"
)
if result == OK:
print("Game saved!")
Notes
- STDJson works with both JSON objects and JSON arrays.
- JSON files are stored as UTF-8 text.
- Saved JSON can be formatted or compact.
- Whole-number floating values are automatically converted into integers.
- Floating-point values containing fractions are preserved.
- Invalid JSON returns
null.
License
This project is licensed under the GNU General Public License v3.0 (GPL-3.0).
You are free to use, modify, and redistribute this software under the terms of the GPL-3.0 license.
See the LICENSE file for the complete license text.
Unlike built-in JSON, in this plug-in 2 is not 2.0; it's 2, and 3.5 is 3.5
Reviews
Quick Information
Unlike built-in JSON, in this plug-in 2 is not 2.0; it's 2, and 3.5 is 3.5