Early Preview
This is currently very much a preview. Please feel free to try things out,
but don't be upset if anything is not yet working. Feedback is welcome over on our
GitHub Dicussions page.
class System.​Text.​Json.​Nodes.​JsonNode
Assembly: System.Text.Json
Inheritance: object → JsonNode
The base class that represents a single node within a mutable JSON document.
Properties
public
JsonNode
Item
public
JsonNode
Item
public
JsonNodeOptions?
Options
Gets the options to control the behavior.
public
JsonNode
Parent
Gets the parent <see cref="T:System.Text.Json.Nodes.JsonNode" /> .
If there is no parent, <see langword="null" /> is returned.
A parent can either be a <see cref="T:System.Text.Json.Nodes.JsonObject" /> or a <see cref="T:System.Text.Json.Nodes.JsonArray" /> .
public
JsonNode
Root
Gets the root <see cref="T:System.Text.Json.Nodes.JsonNode" /> .
Methods
public
JsonArray
AsArray​()
Casts to the derived <see cref="T:System.Text.Json.Nodes.JsonArray" /> type.
Returns A <see cref="T:System.Text.Json.Nodes.JsonArray" /> .
public
JsonObject
AsObject​()
Casts to the derived <see cref="T:System.Text.Json.Nodes.JsonObject" /> type.
Returns A <see cref="T:System.Text.Json.Nodes.JsonObject" /> .
public
JsonValue
AsValue​()
Casts to the derived <see cref="T:System.Text.Json.Nodes.JsonValue" /> type.
Returns A <see cref="T:System.Text.Json.Nodes.JsonValue" /> .
public
JsonNode
DeepClone​()
Creates a new instance of the <see cref="T:System.Text.Json.Nodes.JsonNode" /> class. All child nodes are recursively cloned.
Returns A new cloned instance of the current node.
public static
bool
DeepEquals​(JsonNode node1,
JsonNode node2)
Compares the values of two nodes, including the values of all descendant nodes.
Returns <see langword="true" /> if the tokens are equal; otherwise <see langword="false" /> .
node1
The <see cref="T:System.Text.Json.Nodes.JsonNode" /> to compare.
node2
The <see cref="T:System.Text.Json.Nodes.JsonNode" /> to compare.
public
int
GetElementIndex​()
Returns the index of the current node from the parent <see cref="T:System.Text.Json.Nodes.JsonArray" /> .
Returns The index of the current node.
public
string
GetPath​()
Gets the JSON path.
Returns The JSON Path value.
public
string
GetPropertyName​()
Returns the property name of the current node from the parent object.
Returns The property name of the current node.
public
JsonValueKind
GetValueKind​()
Returns the <see cref="T:System.Text.Json.JsonValueKind" /> of the current instance.
Returns The json value kind of the current instance.
public
T
GetValue​()
Gets the value for the current <see cref="T:System.Text.Json.Nodes.JsonValue" /> .
Returns A value converted from the <see cref="T:System.Text.Json.Nodes.JsonValue" /> instance.
public static
JsonNode
Parse​(IO.​Stream utf8Json,
JsonNodeOptions? nodeOptions = null,
JsonDocumentOptions documentOptions = null)
Parses a <see cref="T:System.IO.Stream" /> as UTF-8-encoded data representing a single JSON value into a <see cref="T:System.Text.Json.Nodes.JsonNode" /> . The Stream will be read to completion.
Returns A <see cref="T:System.Text.Json.Nodes.JsonNode" /> representation of the JSON value, or null if the input represents the null JSON value.
utf8Json
JSON text to parse.
nodeOptions
Options to control the node behavior after parsing.
documentOptions
Options to control the document behavior during parsing.
public static
JsonNode
Parse​(ReadOnlySpan<​byte> utf8Json,
JsonNodeOptions? nodeOptions = null,
JsonDocumentOptions documentOptions = null)
Parses text representing a single JSON value.
Returns A <see cref="T:System.Text.Json.Nodes.JsonNode" /> representation of the JSON value, or null if the input represents the null JSON value.
utf8Json
JSON text to parse.
nodeOptions
Options to control the node behavior after parsing.
documentOptions
Options to control the document behavior during parsing.
public static
JsonNode
Parse​(string json,
JsonNodeOptions? nodeOptions = null,
JsonDocumentOptions documentOptions = null)
Parses text representing a single JSON value.
Returns A <see cref="T:System.Text.Json.Nodes.JsonNode" /> representation of the JSON value, or null if the input represents the null JSON value.
json
JSON text to parse.
nodeOptions
Options to control the node behavior after parsing.
documentOptions
Options to control the document behavior during parsing.
public static
JsonNode
Parse​(Utf8JsonReader& reader,
JsonNodeOptions? nodeOptions = null)
public static
Threading.​Tasks.​Task<​JsonNode>
ParseAsync​(IO.​Stream utf8Json,
JsonNodeOptions? nodeOptions = null,
JsonDocumentOptions documentOptions = null,
Threading.​CancellationToken cancellationToken = null)
Parses a <see cref="T:System.IO.Stream" /> as UTF-8 encoded data representing a single JSON value into a <see cref="T:System.Text.Json.Nodes.JsonNode" /> . The stream will be read to completion.
Returns A <see cref="T:System.Threading.Tasks.Task" /> to produce either a <see cref="T:System.Text.Json.Nodes.JsonNode" /> representation of the JSON value, or null if the input represents the null JSON value.
utf8Json
The JSON text to parse.
nodeOptions
Options to control the node behavior after parsing.
documentOptions
Options to control the document behavior during parsing.
cancellationToken
The token to monitor for cancellation requests.
public
void
ReplaceWith​(T value)
Replaces this node with a new value.
value
The value that replaces this node.
public
string
ToJsonString​(JsonSerializerOptions? options = null)
Converts the current instance to a string in JSON format.
Returns The JSON representation of the current instance.
options
Options to control the serialization behavior.
public
string
ToString​()
Gets a string representation for the current value appropriate to the node type.
Returns A string representation for the current value appropriate to the node type.
public
void
WriteTo​(Utf8JsonWriter writer,
JsonSerializerOptions? options = null)
Writes the <see cref="T:System.Text.Json.Nodes.JsonNode" /> into the provided <see cref="T:System.Text.Json.Utf8JsonWriter" /> as JSON.
writer
The <see cref="T:System.Text.Json.Utf8JsonWriter" /> .
options
Options to control the serialization behavior.
public
bool
Equals​(object obj)
Inherited from object
protected
void
Finalize​()
Inherited from object
public
int
GetHashCode​()
Inherited from object
protected
object
MemberwiseClone​()
Inherited from object