Utf8JsonReader Struct

Definition

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

public value class Utf8JsonReader
public ref struct Utf8JsonReader
type Utf8JsonReader = struct
Public Structure Utf8JsonReader
Inheritance
Utf8JsonReader

Remarks

Utf8JsonReader processes the text sequentially with no caching and by default adheres strictly to the JSON RFC.

When Utf8JsonReader encounters invalid JSON, it throws a JsonException with basic error information like line number and byte position on the line.

Since this type is a ref struct, it doesn't directly support async. However, it does provide support for reentrancy to read incomplete data and to continue reading once more data is presented.

To be able to set max depth while reading or to allow skipping comments, create an instance of JsonReaderOptions and pass it to the reader.

For more information, see Use Utf8JsonReader.

Constructors

Utf8JsonReader(ReadOnlySequence<Byte>, Boolean, JsonReaderState)

Initializes a new instance of the Utf8JsonReader structure that processes a read-only sequence of UTF-8 encoded text and indicates whether the input contains all the text to process.

Utf8JsonReader(ReadOnlySequence<Byte>, JsonReaderOptions)

Initializes a new instance of the Utf8JsonReader structure that processes a read-only sequence of UTF-8 encoded text using the specified options.

Utf8JsonReader(ReadOnlySpan<Byte>, Boolean, JsonReaderState)

Initializes a new instance of the Utf8JsonReader structure that processes a read-only span of UTF-8 encoded text and indicates whether the input contains all the text to process.

Utf8JsonReader(ReadOnlySpan<Byte>, JsonReaderOptions)

Initializes a new instance of the Utf8JsonReader structure that processes a read-only span of UTF-8 encoded text using the specified options.

Properties

BytesConsumed

Gets the total number of bytes consumed so far by this instance of the Utf8JsonReader.

CurrentDepth

Gets the depth of the current token.

CurrentState

Gets the current Utf8JsonReader state to pass to a Utf8JsonReader constructor with more data.

HasValueSequence

Gets a value that indicates which Value property to use to get the token value.

IsFinalBlock

Gets a value that indicates whether all the JSON data was provided or there is more data to come.

Position

Gets the current SequencePosition within the provided UTF-8 encoded input ReadOnlySequence<byte> or a default SequencePosition if the Utf8JsonReader struct was constructed with a ReadOnlySpan<byte>.

TokenStartIndex

Gets the index that the last processed JSON token starts at (within the given UTF-8 encoded input text), skipping any white space.

TokenType

Gets the type of the last processed JSON token in the UTF-8 encoded JSON text.

ValueIsEscaped

Gets a value that indicates whether the current ValueSpan or ValueSequence properties contain escape sequences per RFC 8259 section 7, and therefore require unescaping before being consumed.

ValueSequence

Gets the raw value of the last processed token as a ReadOnlySequence<byte> slice of the input payload, only if the token is contained within multiple segments.

ValueSpan

Gets the raw value of the last processed token as a ReadOnlySpan<byte> 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<byte>.

Methods

CopyString(Span<Byte>)

Copies the current JSON token value from the source, unescaped, as UTF-8 bytes to a buffer.

CopyString(Span<Char>)

Copies the current JSON token value from the source, unescaped, as UTF-16 characters to a buffer.

GetBoolean()

Reads the next JSON token value from the source as a Boolean.

GetByte()

Parses the current JSON token value from the source as a Byte.

GetBytesFromBase64()

Parses the current JSON token value from the source and decodes the Base64 encoded JSON string as a byte array.

GetComment()

Parses the current JSON token value from the source as a comment and transcodes it as a String.

GetDateTime()

Reads the next JSON token value from the source and parses it to a DateTime.

GetDateTimeOffset()

Reads the next JSON token value from the source and parses it to a DateTimeOffset.

GetDecimal()

Reads the next JSON token value from the source and parses it to a Decimal.

GetDouble()

Reads the next JSON token value from the source and parses it to a Double.

GetGuid()

Reads the next JSON token value from the source and parses it to a Guid.

GetInt16()

Parses the current JSON token value from the source as a Int16.

GetInt32()

Reads the next JSON token value from the source and parses it to an Int32.

GetInt64()

Reads the next JSON token value from the source and parses it to an Int64.

GetSByte()

Parses the current JSON token value from the source as an SByte.

GetSingle()

Reads the next JSON token value from the source and parses it to a Single.

GetString()

Reads the next JSON token value from the source unescaped and transcodes it as a string.

GetUInt16()

Parses the current JSON token value from the source as a UInt16.

GetUInt32()

Reads the next JSON token value from the source and parses it to a UInt32.

GetUInt64()

Reads the next JSON token value from the source and parses it to a UInt64.

Read()

Reads the next JSON token from the input source.

Skip()

Skips the children of the current JSON token.

TryGetByte(Byte)

Tries to parse the current JSON token value from the source as a Byte and returns a value that indicates whether the operation succeeded.

TryGetBytesFromBase64(Byte[])

Tries to parse the current JSON token value from the source and decodes the Base64 encoded JSON string as a byte array and returns a value that indicates whether the operation succeeded.

TryGetDateTime(DateTime)

Tries to parse the current JSON token value from the source as a DateTime and returns a value that indicates whether the operation succeeded.

TryGetDateTimeOffset(DateTimeOffset)

Tries to parse the current JSON token value from the source as a DateTimeOffset and returns a value that indicates whether the operation succeeded.

TryGetDecimal(Decimal)

Tries to parse the current JSON token value from the source as a Decimal and returns a value that indicates whether the operation succeeded.

TryGetDouble(Double)

Tries to parse the current JSON token value from the source as a Double and returns a value that indicates whether the operation succeeded.

TryGetGuid(Guid)

Tries to parse the current JSON token value from the source as a Guid and returns a value that indicates whether the operation succeeded.

TryGetInt16(Int16)

Tries to parse the current JSON token value from the source as an Int16 and returns a value that indicates whether the operation succeeded.

TryGetInt32(Int32)

Tries to parse the current JSON token value from the source as an Int32 and returns a value that indicates whether the operation succeeded.

TryGetInt64(Int64)

Tries to parse the current JSON token value from the source as an Int64 and returns a value that indicates whether the operation succeeded.

TryGetSByte(SByte)

Tries to parse the current JSON token value from the source as an SByte and returns a value that indicates whether the operation succeeded.

TryGetSingle(Single)

Tries to parse the current JSON token value from the source as a Single and returns a value that indicates whether the operation succeeded.

TryGetUInt16(UInt16)

Tries to parse the current JSON token value from the source as a UInt16 and returns a value that indicates whether the operation succeeded.

TryGetUInt32(UInt32)

Tries to parse the current JSON token value from the source as a UInt32 and returns a value that indicates whether the operation succeeded.

TryGetUInt64(UInt64)

Tries to parse the current JSON token value from the source as a UInt64 and returns a value that indicates whether the operation succeeded.

TrySkip()

Tries to skip the children of the current JSON token.

ValueTextEquals(ReadOnlySpan<Byte>)

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.

ValueTextEquals(ReadOnlySpan<Char>)

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.

ValueTextEquals(String)

Compares the string text to the unescaped JSON token value in the source and returns a value that indicates whether they match.

Applies to