Table of Contents

Class JsonHelper

Namespace
OpenSettings.Extensions
Assembly
OpenSettings.dll

Provides helper methods for JSON manipulation, including options for reading and writing JSON documents and merging JSON objects.

public static class JsonHelper
Inheritance
JsonHelper
Inherited Members

Properties

DefaultJsonDocumentOptions

Gets the default options for parsing a JSON document, which allows trailing commas and skips comments.

public static JsonDocumentOptions DefaultJsonDocumentOptions { get; }

Property Value

JsonDocumentOptions

DefaultJsonSerializerOptions

Gets the default options for serializing JSON, which allows trailing commas, uses relaxed escaping, and skips comments.

public static JsonSerializerOptions DefaultJsonSerializerOptions { get; }

Property Value

JsonSerializerOptions

DefaultJsonWriterOptions

Gets the default options for writing a JSON document, which does not indent and uses relaxed escaping.

public static JsonWriterOptions DefaultJsonWriterOptions { get; }

Property Value

JsonWriterOptions

Methods

GetJsonFileAsync(string, CancellationToken)

Reads a JSON file asynchronously and returns it as a dictionary.

public static Task<Dictionary<string, object>> GetJsonFileAsync(string filePath, CancellationToken cancellationToken = default)

Parameters

filePath string

The file path of the JSON file to read.

cancellationToken CancellationToken

A cancellation token to support cancellation of the operation.

Returns

Task<Dictionary<string, object>>

A Task containing a Dictionary<string, object> with the JSON data.

Merge(string, string)

Merges two JSON strings (baseJson and patchJson) into a single JSON object.

public static JsonMergeResult Merge(string baseJson, string patchJson)

Parameters

baseJson string

The base JSON string to be merged with the patch.

patchJson string

The JSON string containing the changes to be applied to the base JSON.

Returns

JsonMergeResult

A JsonMergeResult containing the result of the merge operation.

MergeFileAsync(string, string, CancellationToken)

Merges two JSON files asynchronously by reading their contents from the specified file paths.

public static Task<JsonMergeResult> MergeFileAsync(string baseFilePath, string patchFilePath, CancellationToken cancellationToken = default)

Parameters

baseFilePath string

The file path of the base JSON file.

patchFilePath string

The file path of the patch JSON file to apply.

cancellationToken CancellationToken

A cancellation token to support cancellation of the operation.

Returns

Task<JsonMergeResult>

A Task representing the asynchronous operation, with the result as a JsonMergeResult.