Class JsonNodeExtensions
- Namespace
- Songhay.Extensions
- Assembly
- SonghayCore.dll
Extensions of JsonNode.
public static class JsonNodeExtensions
- Inheritance
-
JsonNodeExtensions
- Inherited Members
Remarks
To prevent passing null instances of ILogger into these methods, use AsInstanceOrNullLogger(ILogger?).
Methods
DisplayTopProperties(JsonObject?, int)
Displays top-level JsonObject properties without recursion.
public static string DisplayTopProperties(this JsonObject? jObject, int truncationLength = 16)
Parameters
jObject
JsonObjectthe JsonObject
truncationLength
intthe number of characters to display for each property
Returns
GetJsonValueKind(JsonNode?)
Gets the JsonValueKind of the specified JsonNode.
[Obsolete("For .NET 8 and beyond use `JsonNode.GetValueKind()` instead.")]
public static JsonValueKind GetJsonValueKind(this JsonNode? node)
Parameters
node
JsonNodeThe node.
Returns
Remarks
This member is needed for .NET 6.0 and earlier.
GetPropertyJsonArrayOrNull(JsonNode?, string)
public static JsonArray? GetPropertyJsonArrayOrNull(this JsonNode? node, string propertyName)
Parameters
Returns
GetPropertyJsonObjectOrNull(JsonNode?, string)
public static JsonObject? GetPropertyJsonObjectOrNull(this JsonNode? node, string propertyName)
Parameters
Returns
GetPropertyJsonValueOrNull(JsonNode?, string)
public static JsonValue? GetPropertyJsonValueOrNull(this JsonNode? node, string propertyName)
Parameters
Returns
Remarks
GetPropertyValue<T>(JsonNode?, string)
Gets the property value of the specified JsonNode.
[Obsolete("Use `GetPropertyJsonArrayOrNull`, `GetPropertyJsonObjectOrNull` or `GetPropertyJsonValueOrNull` instead.")]
public static (T? value, bool success) GetPropertyValue<T>(this JsonNode? node, string propertyName)
Parameters
Returns
Type Parameters
T
HasProperty(JsonNode?, string?)
Returns false
when the specified property name does not exist.
public static bool HasProperty(this JsonNode? node, string? propertyName)
Parameters
Returns
IsExpectedObject(JsonNode?, ILogger, params string[])
Determines whether the specified JsonNode is the expected JsonObject.
public static bool IsExpectedObject(this JsonNode? node, ILogger logger, params string[] properties)
Parameters
Returns
RemoveFromParent(JsonNode?, ILogger)
Removes the specified JsonNode when its parent is JsonArray or JsonObject.
public static void RemoveFromParent(this JsonNode? node, ILogger logger)
Parameters
RemoveFromParent(JsonNode?, string?, ILogger)
Removes the specified JsonNode when its parent is JsonArray or JsonObject.
public static void RemoveFromParent(this JsonNode? node, string? propertyName, ILogger logger)
Parameters
node
JsonNodethe JsonNode
propertyName
stringthe name of the property when the specified node is Object
logger
ILoggerthe ILogger
RemoveProperty(JsonNode?, ILogger)
Removes the specified JsonNode when its parent is JsonArray or JsonObject.
public static void RemoveProperty(this JsonNode? node, ILogger logger)
Parameters
RemoveProperty(JsonNode?, string?, ILogger)
Removes the specified JsonNode with the specified property name when the node is JsonObject or JsonArray (array of JsonObject with a property to remove).
public static void RemoveProperty(this JsonNode? node, string? propertyName, ILogger logger)
Parameters
node
JsonNodethe JsonNode
propertyName
stringthe name of the property when the specified node is Object
logger
ILoggerthe ILogger
ToJsonArray(JsonNode?, ILogger)
public static JsonArray? ToJsonArray(this JsonNode? node, ILogger logger)
Parameters
Returns
ToJsonObject(JsonNode?, ILogger)
Converts to the specified JsonNode
to JsonObject or logs failure and returns null
.
public static JsonObject? ToJsonObject(this JsonNode? node, ILogger logger)
Parameters
Returns
WithPropertiesRenamed(JsonObject?, ILogger, params (string oldName, string newName)[])
Returns the specified JsonObject with its properties renamed.
public static JsonObject? WithPropertiesRenamed(this JsonObject? documentData, ILogger logger, params (string oldName, string newName)[] operations)
Parameters
documentData
JsonObjectthe JsonObject
logger
ILoggerthe ILogger
operations
(string oldName, string newName)[]specifies which JsonObject properties to rename