data-formats-resources-vs-json

Data formats: Godot resources vs. JSON

In this series, you learned to save game data using Godot’s resources. It’s a data and file format unique to Godot that makes saving and loading data easy and efficient.

If you look online, some tutorials about saving will recommend another format: JSON.

In this guide, we explain why you should not use JSON to save your players’ data in Godot.

We’ll first explain what JSON is.

What is JSON

The JSON format is a data format native to the JavaScript programming language, which is probably the most used language in the world as it’s the browser’s language.

JSON is a format designed to save and load JavaScript objects to text. It supports JavaScript’s data types and works great when coding in JavaScript.

The JSON equivalent of one of our PlayerSettings resource could look like this:

{
    "player_1_settings": {
        "move_up_action": "move_up",
        "move_down_action": "move_down",
        "move_left_action": "move_left",
        "move_right_action": "move_right",
        "hand_texture_path": "res://path/to/hand_texture.png"
    }
}

Notice how we don’t directly store a Texture for the hand_texture_path: we would have to manually check the path and load the texture as an extra step.

JSON has also become the most common data exchange format between web servers because JavaScript is widespread and JSON data is in human-readable text.

Because every programming language needs to support sending data to the web, JSON is supported everywhere.

You will find people using JSON for all sorts of things because they’re familiar with it, and because every language supports it.

Resources vs. JSON

Godot supports JSON, in addition to many other technologies. You will often use JSON if you need your game to communicate with a web server.

However, there are almost only benefits to using Godot’s resources to save data over JSON:

Also, to use JSON, you need to write extra code in GDScript to prepare data for saving. This makes saving and loading slower as your game’s data expands.

Some would say that one advantage of JSON is that you can write it by hand in a text editor. You can do that with resources, too, but the JSON format is indeed easier to edit.

However, writing data by hand is error-prone and can lead to more bugs compared to doing everything through the editor.

We recommend using resources over JSON to save the player’s game in Godot for all the reasons above.