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.​Utf8JsonReader

Assembly: System.Text.Json

Provides a high-performance API for forward-only, read-only access to UTF-8 encoded JSON text.

Properties

public long
BytesConsumed
Gets the total number of bytes consumed so far by this instance of the <see cref="T:System.Text.Json.Utf8JsonReader" /> .
public int
CurrentDepth
Gets the depth of the current token.
CurrentState
Gets the current <see cref="T:System.Text.Json.Utf8JsonReader" /> state to pass to a <see cref="T:System.Text.Json.Utf8JsonReader" /> constructor with more data.
public bool
HasValueSequence
Gets a value that indicates which <c>Value</c> property to use to get the token value.
public bool
IsFinalBlock
Gets a value that indicates whether all the JSON data was provided or there is more data to come.
Position
Gets the current <see cref="T:System.SequencePosition" /> within the provided UTF-8 encoded input ReadOnlySequence&lt;byte&gt; or a default <see cref="T:System.SequencePosition" /> if the <see cref="T:System.Text.Json.Utf8JsonReader" /> struct was constructed with a ReadOnlySpan&lt;byte&gt;.
public long
TokenStartIndex
Gets the index that the last processed JSON token starts at (within the given UTF-8 encoded input text), skipping any white space.
public JsonTokenType
TokenType
Gets the type of the last processed JSON token in the UTF-8 encoded JSON text.
public bool
ValueIsEscaped
Gets a value that indicates whether the current <see cref="P:System.Text.Json.Utf8JsonReader.ValueSpan" /> or <see cref="P:System.Text.Json.Utf8JsonReader.ValueSequence" /> properties contain escape sequences per RFC 8259 section 7, and therefore require unescaping before being consumed.
public Buffers.​ReadOnlySequence<​byte>
ValueSequence
Gets the raw value of the last processed token as a ReadOnlySequence&lt;byte&gt; slice of the input payload, only if the token is contained within multiple segments.
public ReadOnlySpan<​byte>
ValueSpan
Gets the raw value of the last processed token as a ReadOnlySpan&lt;byte&gt; slice of the input payload, if the token fits in a single segment or if the reader was constructed with a JSON payload contained in a ReadOnlySpan&lt;byte&gt;.

Methods

public int
CopyString​(Span<​byte> utf8Destination)
Copies the current JSON token value from the source, unescaped, as UTF-8 bytes to a buffer.
Returns The number of bytes written to <paramref name="utf8Destination" /> .
utf8Destination A buffer to write the unescaped UTF-8 bytes into.
public int
CopyString​(Span<​char> destination)
Copies the current JSON token value from the source, unescaped, as UTF-16 characters to a buffer.
Returns The number of characters written to <paramref name="destination" /> .
destination A buffer to write the transcoded UTF-16 characters into.
public bool
GetBoolean​()
Reads the next JSON token value from the source as a <see cref="T:System.Boolean" /> .
Returns <see langword="true" /> if the <see cref="P:System.Text.Json.Utf8JsonReader.TokenType" /> is <see cref="F:System.Text.Json.JsonTokenType.True" /> ; <see langword="false" /> if the <see cref="P:System.Text.Json.Utf8JsonReader.TokenType" /> is <see cref="F:System.Text.Json.JsonTokenType.False" /> .
public byte
GetByte​()
Parses the current JSON token value from the source as a <see cref="T:System.Byte" /> .
Returns The value of the UTF-8 encoded token.
public byte[]
GetBytesFromBase64​()
Parses the current JSON token value from the source and decodes the Base64 encoded JSON string as a byte array.
Returns The byte array that represents the current JSON token value.
public string
GetComment​()
Parses the current JSON token value from the source as a comment and transcodes it as a <see cref="T:System.String" /> .
Returns The comment that represents the current JSON token value.
public DateTime
GetDateTime​()
Reads the next JSON token value from the source and parses it to a <see cref="T:System.DateTime" /> .
Returns The date and time value, if the entire UTF-8 encoded token value can be successfully parsed.
GetDateTimeOffset​()
Reads the next JSON token value from the source and parses it to a <see cref="T:System.DateTimeOffset" /> .
Returns The date and time offset, if the entire UTF-8 encoded token value can be successfully parsed.
public decimal
GetDecimal​()
Reads the next JSON token value from the source and parses it to a <see cref="T:System.Decimal" /> .
Returns The UTF-8 encoded token value parsed to a <see cref="T:System.Decimal" /> .
public double
GetDouble​()
Reads the next JSON token value from the source and parses it to a <see cref="T:System.Double" /> .
Returns The UTF-8 encoded token value parsed to a <see cref="T:System.Double" /> .
public Guid
GetGuid​()
Reads the next JSON token value from the source and parses it to a <see cref="T:System.Guid" /> .
Returns The GUID value, if the entire UTF-8 encoded token value can be successfully parsed.
public short
GetInt16​()
Parses the current JSON token value from the source as a <see cref="T:System.Int16" /> .
Returns The UTF-8 encoded token value parsed to an <see cref="T:System.Int16" /> .
public int
GetInt32​()
Reads the next JSON token value from the source and parses it to an <see cref="T:System.Int32" /> .
Returns The UTF-8 encoded token value parsed to an <see cref="T:System.Int32" /> .
public long
GetInt64​()
Reads the next JSON token value from the source and parses it to an <see cref="T:System.Int64" /> .
Returns The UTF-8 encoded token value parsed to an <see cref="T:System.Int64" /> .
public sbyte
GetSByte​()
Parses the current JSON token value from the source as an <see cref="T:System.SByte" /> .
Returns The UTF-8 encoded token value parsed to an <see cref="T:System.SByte" /> .
public Single
GetSingle​()
Reads the next JSON token value from the source and parses it to a <see cref="T:System.Single" /> .
Returns The UTF-8 encoded token value parsed to a <see cref="T:System.Single" /> .
public string
GetString​()
Reads the next JSON token value from the source unescaped and transcodes it as a string.
Returns The token value parsed to a string, or <see langword="null" /> if <see cref="P:System.Text.Json.Utf8JsonReader.TokenType" /> is <see cref="F:System.Text.Json.JsonTokenType.Null" /> .
public ushort
GetUInt16​()
Parses the current JSON token value from the source as a <see cref="T:System.UInt16" /> .
Returns The UTF-8 encoded token value parsed to a <see cref="T:System.UInt16" /> .
public uint
GetUInt32​()
Reads the next JSON token value from the source and parses it to a <see cref="T:System.UInt32" /> .
Returns The UTF-8 encoded token value parsed to a <see cref="T:System.UInt32" /> .
public ulong
GetUInt64​()
Reads the next JSON token value from the source and parses it to a <see cref="T:System.UInt64" /> .
Returns The UTF-8 encoded token value parsed to a <see cref="T:System.UInt64" /> .
public bool
Read​()
Reads the next JSON token from the input source.
Returns <see langword="true" /> if the token was read successfully; otherwise, <see langword="false" /> .
public void
Skip​()
Skips the children of the current JSON token.
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
TryGetSByte​(SByte& value)
public bool
TryGetSingle​(Single& value)
public bool
TryGetUInt16​(UInt16& value)
public bool
TryGetUInt32​(UInt32& value)
public bool
TryGetUInt64​(UInt64& value)
public bool
TrySkip​()
Tries to skip the children of the current JSON token.
Returns <see langword="true" /> if there was enough data for the children to be skipped successfully; otherwise, <see langword="false" /> .
public bool
ValueTextEquals​(ReadOnlySpan<​byte> utf8Text)
Compares the UTF-8 encoded text in a read-only byte span to the unescaped JSON token value in the source and returns a value that indicates whether they match.
Returns <see langword="true" /> if the JSON token value in the source matches the UTF-8 encoded lookup text; otherwise, <see langword="false" /> .
utf8Text The UTF-8 encoded text to compare against.
public bool
ValueTextEquals​(ReadOnlySpan<​char> text)
Compares the text in a read-only character span to the unescaped JSON token value in the source and returns a value that indicates whether they match.
Returns <see langword="true" /> if the JSON token value in the source matches the lookup text; otherwise, <see langword="false" /> .
text The text to compare against.
public bool
ValueTextEquals​(string text)
Compares the string text to the unescaped JSON token value in the source and returns a value that indicates whether they match.
Returns <see langword="true" /> if the JSON token value in the source matches the lookup text; otherwise, <see langword="false" /> .
text The text to compare against.
public bool
Equals​(object obj)
Inherited from ValueType
public int
GetHashCode​()
Inherited from ValueType
public string
ToString​()
Inherited from ValueType
protected void
Finalize​()
Inherited from object
public Type
GetType​()
Inherited from object
protected object
MemberwiseClone​()
Inherited from object