Class JsonReader
Lightweight helpers for loading and saving JSON configuration files. Provides typed object and Newtonsoft.Json.Linq.JObject utilities and ensures parent directories exist before writes.
Inheritance
Namespace: Wss.CoreModule
Assembly: WSS_Core_Interface.dll
Syntax
public static class JsonReader
Methods
LoadJObject(string, JObject)
Loads a JSON file into a Newtonsoft.Json.Linq.JObject. If the file is missing,
writes defaults to disk and returns it.
Declaration
public static JObject LoadJObject(string path, JObject defaults)
Parameters
| Type | Name | Description |
|---|---|---|
| string | path | File path to read from. |
| JObject | defaults | Default JSON object to persist and return when missing. |
Returns
| Type | Description |
|---|---|
| JObject | Parsed Newtonsoft.Json.Linq.JObject. |
LoadObject<T>(string, T)
Loads a JSON file into a typed object. If the file is missing or invalid,
writes defaults to disk and returns it.
Declaration
public static T LoadObject<T>(string path, T defaults) where T : class
Parameters
| Type | Name | Description |
|---|---|---|
| string | path | File path to read from. |
| T | defaults | Default instance to persist and return when missing/invalid. |
Returns
| Type | Description |
|---|---|
| T | The deserialized object, or |
Type Parameters
| Name | Description |
|---|---|
| T | Reference type to deserialize to. |
SaveJObject(string, JObject)
Writes a Newtonsoft.Json.Linq.JObject to disk with indented formatting. Ensures the parent directory exists.
Declaration
public static void SaveJObject(string path, JObject obj)
Parameters
| Type | Name | Description |
|---|---|---|
| string | path | Destination file path. |
| JObject | obj | JSON object to write. |
SaveObject<T>(string, T)
Serializes obj to indented JSON at path.
Creates the parent directory when needed.
Declaration
public static void SaveObject<T>(string path, T obj)
Parameters
| Type | Name | Description |
|---|---|---|
| string | path | Destination file path. |
| T | obj | Object to serialize. |
Type Parameters
| Name | Description |
|---|---|
| T | Type of the object to serialize. |