Class JsonHelpers

Namespace
Elegy.Common.Text
Assembly
Elegy.Common.dll

JSON reading and writing utilities.

public static class JsonHelpers
Inheritance
JsonHelpers
Inherited Members

Fields

Options

The default JSON serialisation options.

public static readonly JsonSerializerOptions Options

Field Value

JsonSerializerOptions

Methods

Create(JsonSerializerOptions)

Creates a JsonSerializerOptions which has the basic properties of Options, but the converters of options.

public static JsonSerializerOptions Create(JsonSerializerOptions options)

Parameters

options JsonSerializerOptions

Returns

JsonSerializerOptions

LoadFrom<T>(string)

Reads JSON data from path and returns it as a/an T.

public static T? LoadFrom<T>(string path) where T : class

Parameters

path string

Returns

T

true on success, false if the file cannot be found.

Type Parameters

T

LoadFrom<T>(string, JsonSerializerOptions)

Reads JSON data from path and returns it as a/an T. Also uses custom JSON serialisation options.

public static T? LoadFrom<T>(string path, JsonSerializerOptions options) where T : class

Parameters

path string
options JsonSerializerOptions

Returns

T

true on success, false if the file cannot be found.

Type Parameters

T

LoadFrom<T>(ref T, string)

Reads JSON data from path and stores it into outObject.

public static bool LoadFrom<T>(ref T outObject, string path) where T : struct

Parameters

outObject T
path string

Returns

bool

true on success, false if the file cannot be found.

Type Parameters

T

LoadFrom<T>(ref T, string, JsonSerializerOptions)

Reads JSON data from path and stores it into outObject. Uses custom options also.

public static bool LoadFrom<T>(ref T outObject, string path, JsonSerializerOptions options) where T : struct

Parameters

outObject T
path string
options JsonSerializerOptions

Returns

bool

true on success, false if the file cannot be found.

Type Parameters

T

Write<T>(T, string)

Writes what into a file path.

public static bool Write<T>(T what, string path)

Parameters

what T
path string

Returns

bool

true on success, false if the path is invalid.

Type Parameters

T