Share via

Utf8JsonReader.ValueSpan Property


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

 property ReadOnlySpan<System::Byte> ValueSpan { ReadOnlySpan<System::Byte> get(); };
public ReadOnlySpan<byte> ValueSpan { get; }
member this.ValueSpan : ReadOnlySpan<byte>
Public ReadOnly Property ValueSpan As ReadOnlySpan(Of Byte)

Property Value

A read-only span of bytes.


If the JSON is provided within a ReadOnlySequence<byte> and the slice that represents the token value fits in a single segment, then ValueSpan contains the sliced value since it can be represented as a span. Otherwise, ValueSequence contains the token value.

If HasValueSequence is true, ValueSpan is empty. Therefore, only access ValueSpan if HasValueSequence is false. Otherwise, the token value must be accessed from ValueSequence.

There is no guarantee that this property will always contain well-formed data. If the input JSON passed in to the Utf8JsonReader contains invalid UTF-8 bytes within JSON string tokens, this property will return back those invalid UTF-8 bytes as is. Therefore, if the input is untrusted or not previously validated, call GetString() to get the JSON string token.

Since this property returns the raw bytes, avoid using it for text comparison. Instead call ValueTextEquals which unescapes the text if necessary.

Applies to