Skip to content

Utf8JsonReader

Definition

Namespace: Corvus.Text.Json
Assembly: Corvus.Text.Json.dll
Source: Utf8JsonReader.cs

Provides a high-performance API for forward-only, read-only access to the UTF-8 encoded JSON text. It processes the text sequentially with no caching and adheres strictly to the JSON RFC by default (https:// tools.ietf.org/html/rfc8259). When it 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 does not directly support async. However, it does provide support for reentrancy to read incomplete data, and continue reading once more data is presented. To be able to set max depth while reading OR allow skipping comments, create an instance of JsonReaderState and pass that in to the reader.

public readonly struct Utf8JsonReader

Constructors

Constructor Description
Utf8JsonReader(...) Constructs a new Utf8JsonReader instance.

Properties

Property Type Description
BytesConsumed long Returns the total amount of bytes consumed by the Utf8JsonReader so far for the current instance of the...
CurrentDepth int Tracks the recursive depth of the nested objects / arrays within the JSON text processed so far. This provides the depth of the current token.
CurrentState JsonReaderState Returns the current snapshot of the Utf8JsonReader state which must be captured by the caller and passed back in to the...
HasValueSequence bool Lets the caller know which of the two 'Value' properties to read to get the token value. For input data within a ReadOnlySpan this will always return false. For input data within a ReadOnlySe...
IsFinalBlock bool Returns the mode of this instance of the Utf8JsonReader. True when the reader was constructed with the input span containing the entire data to pro...
Position SequencePosition Returns the current SequencePosition within the provided UTF-8 encoded input ReadOnlySequence. If the...
TokenStartIndex long Returns the index that the last processed JSON token starts at within the given UTF-8 encoded input text, skipping any white space.
TokenType JsonTokenType Gets the type of the last processed JSON token in the UTF-8 encoded JSON text.
ValueIsEscaped bool Lets the caller know whether the current ValueSpan or ValueSequence prope...
ValueSequence ReadOnlySequence<byte> Gets the value of the last processed token as a ReadOnlySpan slice of the input payload. If the JSON is provided within a ReadOnlySequence and the slice that represents the token value...
ValueSpan ReadOnlySpan<byte> Gets the value of the last processed token as a ReadOnlySpan slice of the input payload. If the JSON is provided within a ReadOnlySequence and the slice that represents the token value...

Methods

Method Description
CopyString Copies the current JSON token value from the source, unescaped as a UTF-8 string to the destination buffer.
GetBoolean() Parses the current JSON token value from the source as a Boolean. Returns true if the TokenType is JsonTokenType.True and false if the...
GetByte() Parses the current JSON token value from the source as a Byte. Returns the value if the entire UTF-8 encoded token value can be successfully...
GetBytesFromBase64() Parses the current JSON token value from the source and decodes the Base64 encoded JSON string as bytes.
GetComment() Parses the current JSON token value from the source as a comment, transcoded as a String.
GetDateTime() Parses the current JSON token value from the source as a DateTime. Returns the value if the entire UTF-8 encoded token value can be succe...
GetDateTimeOffset() Parses the current JSON token value from the source as a DateTimeOffset. Returns the value if the entire UTF-8 encoded token value...
GetDecimal() Parses the current JSON token value from the source as a Decimal. Returns the value if the entire UTF-8 encoded token value can be success...
GetDouble() Parses the current JSON token value from the source as a Double. Returns the value if the entire UTF-8 encoded token value can be successfu...
GetGuid() Parses the current JSON token value from the source as a Guid. Returns the value if the entire UTF-8 encoded token value can be successfully...
GetInt16() Parses the current JSON token value from the source as a Int16. Returns the value if the entire UTF-8 encoded token value can be successfull...
GetInt32() Parses the current JSON token value from the source as an Int32. Returns the value if the entire UTF-8 encoded token value can be successful...
GetInt64() Parses the current JSON token value from the source as a Int64. Returns the value if the entire UTF-8 encoded token value can be successfull...
GetSByte() Parses the current JSON token value from the source as an SByte. Returns the value if the entire UTF-8 encoded token value can be successful...
GetSingle() Parses the current JSON token value from the source as a Single. Returns the value if the entire UTF-8 encoded token value can be successfu...
GetString() Parses the current JSON token value from the source, unescaped, and transcoded as a String.
GetUInt16() Parses the current JSON token value from the source as a UInt16. Returns the value if the entire UTF-8 encoded token value can be successfu...
GetUInt32() Parses the current JSON token value from the source as a UInt32. Returns the value if the entire UTF-8 encoded token value can be successfu...
GetUInt64() Parses the current JSON token value from the source as a UInt64. Returns the value if the entire UTF-8 encoded token value can be successfu...
Read() Read the next JSON token from input source.
Skip() Skips the children of the current JSON token.
TryGetByte(ref byte) Parses the current JSON token value from the source as a Byte. Returns true if the entire UTF-8 encoded token value can be successfully par...
TryGetBytesFromBase64(ref byte[]) Parses the current JSON token value from the source and decodes the Base64 encoded JSON string as bytes. Returns true if the entire token value is encoded as valid Base64 text and can be successf...
TryGetDateTime(ref DateTime) Parses the current JSON token value from the source as a DateTime. Returns true if the entire UTF-8 encoded token value can be successf...
TryGetDateTimeOffset(ref DateTimeOffset) Parses the current JSON token value from the source as a DateTimeOffset. Returns true if the entire UTF-8 encoded token value can...
TryGetDecimal(ref decimal) Parses the current JSON token value from the source as a Decimal. Returns true if the entire UTF-8 encoded token value can be successful...
TryGetDouble(ref double) Parses the current JSON token value from the source as a Double. Returns true if the entire UTF-8 encoded token value can be successfully...
TryGetGuid(ref Guid) Parses the current JSON token value from the source as a Guid. Returns true if the entire UTF-8 encoded token value can be successfully par...
TryGetInt16(ref short) Parses the current JSON token value from the source as a Int16. Returns true if the entire UTF-8 encoded token value can be successfully p...
TryGetInt32(ref int) Parses the current JSON token value from the source as an Int32. Returns true if the entire UTF-8 encoded token value can be successfully...
TryGetInt64(ref long) Parses the current JSON token value from the source as a Int64. Returns true if the entire UTF-8 encoded token value can be successfully p...
TryGetSByte(ref sbyte) Parses the current JSON token value from the source as an SByte. Returns true if the entire UTF-8 encoded token value can be successfully...
TryGetSingle(ref float) Parses the current JSON token value from the source as a Single. Returns true if the entire UTF-8 encoded token value can be successfully...
TryGetUInt16(ref ushort) Parses the current JSON token value from the source as a UInt16. Returns true if the entire UTF-8 encoded token value can be successfully...
TryGetUInt32(ref uint) Parses the current JSON token value from the source as a UInt32. Returns true if the entire UTF-8 encoded token value can be successfully...
TryGetUInt64(ref ulong) Parses the current JSON token value from the source as a UInt64. Returns true if the entire UTF-8 encoded token value can be successfully...
TrySkip() Tries to skip the children of the current JSON token.
ValueTextEquals Compares the UTF-8 encoded text to the unescaped JSON token value in the source and returns true if they match.

Applies To

Product Versions
.NET 9, 10
.NET Standard 2.0, 2.1

Collaborate with us on GitHub

The source for this content can be found on GitHub, where you can also create and review issues and pull requests.

Open an issue