> For the complete documentation index, see [llms.txt](https://pahutyakv.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://pahutyakv.gitbook.io/docs/savely/json.md).

# JSON

**Savely.JSON** provides simple, fast JSON-based data persistence using Unity’s built-in

JsonUtility. It is ideal for lightweight save files, configuration data, or any serializable game structs/classes.

***

### <mark style="color:$success;">**Saving Data**</mark>

Serializes any Unity-serializable type (`JsonUtility` compatible) into a JSON file.

```csharp
Savely.JSON.Save("player_profile", profileData);
```

`prettyPrint` is useful for debugging or reading configuration files.

```csharp
Savely.JSON.Save("settings", settings, prettyPrint: true);
```

If `data` is `null`, an exception is thrown.

***

### <mark style="color:$success;">**Loading Data**</mark>

```csharp
PlayerData profile = Savely.JSON.Load("player_profile", defaultValue);
```

* Returns `defaultValue` if the file does not exist.
* Returns `defaultValue` if JSON parsing fails.
* Logs a warning on load error.

***

### <mark style="color:$success;">**Check if File Exists**</mark>

This checks within the active Savely root directory.

```csharp
bool exists = Savely.JSON.Exists("player_profile");
```

***

### <mark style="color:$success;">**Deleting a File**</mark>

If the file does not exist, nothing happens.

```csharp
Savely.JSON.Delete("player_profile");
```

***

### <mark style="color:$success;">**Changing the File Extension**</mark>

You can customize the extension if needed (e.g., `.data`, `.cfg`, etc.).

```csharp
Savely.JSON.SetExtension("data");
```

***

### <mark style="color:$warning;">**Requirements & Limitations**</mark>

Supported:

* Unity types supported by `JsonUtility`
* Serializable classes
* Serializable structs
* Fields with `[SerializeField]`
* Primitive types
* Enums

Limitations:

* `JsonUtility` does not support dictionaries.
* `JsonUtility` does not support complex polymorphism.
* `null` values cannot be serialized for reference types.
