> For the complete documentation index, see [llms.txt](https://walksy.gitbook.io/walksylib-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://walksy.gitbook.io/walksylib-docs/using/saving-and-loading.md).

# Saving and Loading

WalksyLib saves and loads configs automatically. In most cases you'll never call `load()` or `save()` yourself.

## Saving manually

If your mod changes a value outside the config screen (for example, a keybind that toggles a setting), save it yourself:

```java
new MyModConfig().getConfig().save();
```

`saveAndNotify()` also runs your `onSave` callback.

## The file format

Configs are JSON, organised by category, then group, then option save key.&#x20;

## Error handling

| Situation               | Result                                                                        |
| ----------------------- | ----------------------------------------------------------------------------- |
| File missing            | Defaults are used and the file is created.                                    |
| Invalid JSON            | The file is backed up to `<name>.json.corrupt.bak`, and defaults are kept.    |
| One value can't be read | That option keeps its default, an error is logged, and everything else loads. |
| Old WalksyLib format    | Migrated automatically, with a `.legacy.bak` backup.                          |

## Moving a config file

If you change `.path(...)`, add `.movedFrom(oldPath)` so users keep their settings:

```java
Config.builder()
    .path(PathUtils.ofConfigDir("mymod"))
    .movedFrom(PathUtils.ofConfigDir("my-old-mod-name"))
```

On the next load, the old file's values are imported and the old file is renamed to `.moved.bak`.
