JsonNode – .NET 8 API updates
Part of .NET 8, JsonNode
and JsonArray
get a few new additions to their API. We’ve already covered deep copy and deep equality in an earlier article, but there’s more.
GetValueKind
public JsonValueKind GetValueKind(JsonSerializerOptions options = null);
Code language: C# (cs)
Returns the JsonValueKind
of the current instance.
GetPropertyName
public string GetPropertyName();
Code language: C# (cs)
Returns property name of the current node from the parent object. Throws an InvalidOperationException
if the parent is not a JsonObject
.
GetElementIndex
public int GetElementIndex();
Code language: C# (cs)
Returns the index of the current node from the parent JsonArray
. Throws an InvalidOperationException
if the parent is not a JsonArray
.
ReplaceWith<T>
public void ReplaceWith<T>(T value);
Code language: C# (cs)
Replaces the given node with the provided value.
ParseAsync
public static Task<JsonNode?> ParseAsync(
Stream utf8Json,
JsonNodeOptions? nodeOptions = null,
JsonDocumentOptions documentOptions = default,
CancellationToken cancellationToken = default);
Code language: C# (cs)
Asynchronously parses a stream of UTF-8 encoded data representing a single JSON value into a JsonNode
.
One Comment