GDExtension for Godot engine that parses YAML files. It uses Rapid YAML library.
Download a release and extract it into your project directory. If you built from source, copy the contents into addons/YAML
. The editor will automatically detect the extension and enable it and you will be able to use it right away.
The extension comes with a YAML class that provides 2 static methods: parse_string()
and parse_file()
. The latter is the same as the former, except it loads a file as text and then parses the content.
The class works similarly to built-in JSON class. parse_string()
will return a Variant, which is the result of parsing.
var string = """
- 1
- 2
- 3
"""
print(YAML.parse_string(string)) # Prints "[1, 2, 3]".
The extension is able to load Godot's native types, like Vector2. However, since YAML does not support Godot type syntax, you need to enclose them in quotes.
var string = """
"Vector2i(0, 0)": Epicenter
"Vector2i(1, 0)": Eastern Corridor
"""
var data = YAML.parse_string(string) # Returns a Dictionary with Vector2i keys.
If a string fails to parse, the result will be null
. If parse_file()
fails to open the file, it will also return null
.
- Only parsing is supported, no writing.
- The extension has no error handling like JSON class. Errors are simply printed to output.
- Limitations of Rapid YAML apply.
You can find all my addons on my profile page.