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.

struct System.​Text.​Json.​JsonElement

Assembly: System.Text.Json

Represents a specific JSON value within a <see cref="T:System.Text.Json.JsonDocument" /> .

Properties

public JsonElement
Item
public JsonValueKind
ValueKind
Gets the type of the current JSON value.

Methods

public JsonElement
Clone​()
Gets a JsonElement that can be safely stored beyond the lifetime of the original <see cref="T:System.Text.Json.JsonDocument" /> .
Returns A JsonElement that can be safely stored beyond the lifetime of the original <see cref="T:System.Text.Json.JsonDocument" /> .
public static bool
DeepEquals​(JsonElement element1, JsonElement element2)
Compares the values of two <see cref="T:System.Text.Json.JsonElement" /> values for equality, including the values of all descendant elements.
Returns <see langword="true" /> if the two values are equal; otherwise, <see langword="false" /> .
element1 The first <see cref="T:System.Text.Json.JsonElement" /> to compare.
element2 The second <see cref="T:System.Text.Json.JsonElement" /> to compare.
EnumerateArray​()
Gets an enumerator to enumerate the values in the JSON array represented by this JsonElement.
Returns An enumerator to enumerate the values in the JSON array represented by this JsonElement.
EnumerateObject​()
Gets an enumerator to enumerate the properties in the JSON object represented by this JsonElement.
Returns An enumerator to enumerate the properties in the JSON object represented by this JsonElement.
public int
GetArrayLength​()
Gets the number of values contained within the current array value.
Returns The number of values contained within the current array value.
public bool
GetBoolean​()
Gets the value of the element as a <see cref="T:System.Boolean" /> .
Returns The value of the element as a <see cref="T:System.Boolean" /> .
public byte
GetByte​()
Gets the current JSON number as a <see cref="T:System.Byte" /> .
Returns The current JSON number as a <see cref="T:System.Byte" /> .
public byte[]
GetBytesFromBase64​()
Gets the value of the element as a byte array.
Returns The value decoded as a byte array.
public DateTime
GetDateTime​()
Gets the value of the element as a <see cref="T:System.DateTime" /> .
Returns The value of the element as a <see cref="T:System.DateTime" /> .
GetDateTimeOffset​()
Gets the value of the element as a <see cref="T:System.DateTimeOffset" /> .
Returns The value of the element as a <see cref="T:System.DateTimeOffset" /> .
public decimal
GetDecimal​()
Gets the current JSON number as a <see cref="T:System.Decimal" /> .
Returns The current JSON number as a <see cref="T:System.Decimal" /> .
public double
GetDouble​()
Gets the current JSON number as a <see cref="T:System.Double" /> .
Returns The current JSON number as a <see cref="T:System.Double" /> .
public Guid
GetGuid​()
Gets the value of the element as a <see cref="T:System.Guid" /> .
Returns The value of the element as a <see cref="T:System.Guid" /> .
public short
GetInt16​()
Gets the current JSON number as an <see cref="T:System.Int16" /> .
Returns The current JSON number as an <see cref="T:System.Int16" /> .
public int
GetInt32​()
Gets the current JSON number as an <see cref="T:System.Int32" /> .
Returns The current JSON number as an <see cref="T:System.Int32" /> .
public long
GetInt64​()
Gets the current JSON number as an <see cref="T:System.Int64" /> .
Returns The current JSON number as an <see cref="T:System.Int64" /> .
public JsonElement
GetProperty​(ReadOnlySpan<​byte> utf8PropertyName)
Gets a <see cref="T:System.Text.Json.JsonElement" /> representing the value of a required property identified by <paramref name="utf8PropertyName" /> .
Returns A <see cref="T:System.Text.Json.JsonElement" /> representing the value of the requested property.
utf8PropertyName The UTF-8 representation (with no Byte-Order-Mark (BOM)) of the name of the property to return.
public JsonElement
GetProperty​(ReadOnlySpan<​char> propertyName)
Gets a <see cref="T:System.Text.Json.JsonElement" /> representing the value of a required property identified by <paramref name="propertyName" /> .
Returns A <see cref="T:System.Text.Json.JsonElement" /> representing the value of the requested property.
propertyName The name of the property whose value is to be returned.
public JsonElement
GetProperty​(string propertyName)
Gets a <see cref="T:System.Text.Json.JsonElement" /> representing the value of a required property identified by <paramref name="propertyName" /> .
Returns A <see cref="T:System.Text.Json.JsonElement" /> representing the value of the requested property.
propertyName The name of the property whose value is to be returned.
public int
GetPropertyCount​()
Gets the number of properties contained within the current object value.
Returns The number of properties contained within the current object value.
public string
GetRawText​()
Gets a string that represents the original input data backing this value.
Returns The original input data backing this value.
public sbyte
GetSByte​()
Gets the current JSON number as an <see cref="T:System.SByte" /> .
Returns The current JSON number as an <see cref="T:System.SByte" /> .
public Single
GetSingle​()
Gets the current JSON number as a <see cref="T:System.Single" /> .
Returns The current JSON number as a <see cref="T:System.Single" /> .
public string
GetString​()
Gets the value of the element as a <see cref="T:System.String" /> .
Returns The value of the element as a <see cref="T:System.String" /> .
public ushort
GetUInt16​()
Gets the current JSON number as a <see cref="T:System.UInt16" /> .
Returns The current JSON number as a <see cref="T:System.UInt16" /> .
public uint
GetUInt32​()
Gets the current JSON number as a <see cref="T:System.UInt32" /> .
Returns The current JSON number as a <see cref="T:System.UInt32" /> .
public ulong
GetUInt64​()
Gets the current JSON number as a <see cref="T:System.UInt64" /> .
Returns The current JSON number as a <see cref="T:System.UInt64" /> .
public static JsonElement
Parse​(ReadOnlySpan<​byte> utf8Json, JsonDocumentOptions options = null)
Parses UTF8-encoded text representing a single JSON value into a <see cref="T:System.Text.Json.JsonElement" /> .
Returns A <see cref="T:System.Text.Json.JsonElement" /> representation of the JSON value.
utf8Json The JSON text to parse.
options Options to control the reader behavior during parsing.
public static JsonElement
Parse​(ReadOnlySpan<​char> json, JsonDocumentOptions options = null)
Parses text representing a single JSON value into a <see cref="T:System.Text.Json.JsonElement" /> .
Returns A <see cref="T:System.Text.Json.JsonElement" /> representation of the JSON value.
json The JSON text to parse.
options Options to control the reader behavior during parsing.
public static JsonElement
Parse​(string json, JsonDocumentOptions options = null)
Parses text representing a single JSON value into a <see cref="T:System.Text.Json.JsonElement" /> .
Returns A <see cref="T:System.Text.Json.JsonElement" /> representation of the JSON value.
json The JSON text to parse.
options Options to control the reader behavior during parsing.
public static JsonElement
ParseValue​(Utf8JsonReader& reader)
public string
ToString​()
Gets a string representation for the current value appropriate to the value type.
Returns A string representation for the current value appropriate to the value type.
public bool
TryGetByte​(Byte& value)
public bool
TryGetBytesFromBase64​(Byte[]& value)
public bool
TryGetDateTime​(DateTime& value)
public bool
TryGetDateTimeOffset​(DateTimeOffset& value)
public bool
TryGetDecimal​(Decimal& value)
public bool
TryGetDouble​(Double& value)
public bool
TryGetGuid​(Guid& value)
public bool
TryGetInt16​(Int16& value)
public bool
TryGetInt32​(Int32& value)
public bool
TryGetInt64​(Int64& value)
public bool
TryGetProperty​(ReadOnlySpan<​byte> utf8PropertyName, JsonElement& value)
public bool
TryGetProperty​(ReadOnlySpan<​char> propertyName, JsonElement& value)
public bool
TryGetProperty​(string propertyName, JsonElement& value)
public bool
TryGetSByte​(SByte& value)
public bool
TryGetSingle​(Single& value)
public bool
TryGetUInt16​(UInt16& value)
public bool
TryGetUInt32​(UInt32& value)
public bool
TryGetUInt64​(UInt64& value)
public static bool
TryParseValue​(Utf8JsonReader& reader, Nullable`1& element)
public bool
ValueEquals​(ReadOnlySpan<​byte> utf8Text)
Compares the text represented by a UTF8-encoded byte span to the string value of this element.
Returns <see langword="true" /> if the string value of this element has the same UTF-8 encoding as <paramref name="utf8Text" /> ; otherwise, <see langword="false" /> .
utf8Text The UTF-8 encoded text to compare against.
public bool
ValueEquals​(ReadOnlySpan<​char> text)
Compares a specified read-only character span to the string value of this element.
Returns <see langword="true" /> if the string value of this element matches <paramref name="text" /> ; otherwise, <see langword="false" /> .
text The text to compare against.
public bool
ValueEquals​(string text)
Compares a specified string to the string value of this element.
Returns <see langword="true" /> if the string value of this element matches <paramref name="text" /> ; otherwise, <see langword="false" /> .
text The text to compare against.
public void
WriteTo​(Utf8JsonWriter writer)
Writes the element to the specified writer as a JSON value.
writer The writer to which to write the element.
public bool
Equals​(object obj)
Inherited from ValueType
public int
GetHashCode​()
Inherited from ValueType
protected void
Finalize​()
Inherited from object
public Type
GetType​()
Inherited from object
protected object
MemberwiseClone​()
Inherited from object