Table of Contents

Class JsonSerializerExtensions

Namespace
Nerdbank.Json
Assembly
Nerdbank.Json.dll

Extension methods for the JsonSerializer class.

public static class JsonSerializerExtensions
Inheritance
JsonSerializerExtensions
Inherited Members

Remarks

These extension methods preserve the convenient serializer entry points for target frameworks that cannot use the constrained IShapeable<T> instance overloads, and for values that rely on dynamic shape discovery or witness types.

Some of these methods will be very typical when targeting .NET Standard or .NET Framework, but when targeting .NET, the compiler will prefer the instance methods on the JsonSerializer class itself. These instance methods are faster and produce compile errors rather than runtime exceptions that may be thrown by these extension methods.

Methods

DeserializeEnumerableAsync<T>(JsonSerializer, PipeReader, SequenceOptions, CancellationToken)

Asynchronously streams JSON values using the selected framing.

public static IAsyncEnumerable<T?> DeserializeEnumerableAsync<T>(this JsonSerializer self, PipeReader reader, JsonSerializer.SequenceOptions options = default, CancellationToken cancellationToken = default)

Parameters

self JsonSerializer
reader PipeReader

The pipe to read from. It is advanced but never completed by this method.

options JsonSerializer.SequenceOptions

The framing options. The default is newline-delimited JSON.

cancellationToken CancellationToken

A cancellation token.

Returns

IAsyncEnumerable<T>

An asynchronous sequence of values.

Type Parameters

T

The value type.

Exceptions

JsonSerializationException

Thrown if deserialization or newline framing fails.

DeserializeEnumerableAsync<T>(JsonSerializer, Stream, SequenceOptions, CancellationToken)

Asynchronously streams JSON values from a stream using the selected framing.

public static IAsyncEnumerable<T?> DeserializeEnumerableAsync<T>(this JsonSerializer self, Stream stream, JsonSerializer.SequenceOptions options = default, CancellationToken cancellationToken = default)

Parameters

self JsonSerializer
stream Stream

The stream to read from. It is read but not disposed or closed by this method.

options JsonSerializer.SequenceOptions

The framing options. The default is newline-delimited JSON.

cancellationToken CancellationToken

A cancellation token.

Returns

IAsyncEnumerable<T>

An asynchronous sequence of values.

Type Parameters

T

The value type.

DeserializeEnumerableAsync<T, TProvider>(JsonSerializer, PipeReader, SequenceOptions, CancellationToken)

Asynchronously streams JSON values using the selected framing.

public static IAsyncEnumerable<T?> DeserializeEnumerableAsync<T, TProvider>(this JsonSerializer self, PipeReader reader, JsonSerializer.SequenceOptions options = default, CancellationToken cancellationToken = default)

Parameters

self JsonSerializer
reader PipeReader

The pipe to read from. It is advanced but never completed by this method.

options JsonSerializer.SequenceOptions

The framing options. The default is newline-delimited JSON.

cancellationToken CancellationToken

A cancellation token.

Returns

IAsyncEnumerable<T>

An asynchronous sequence of values.

Type Parameters

T

The value type.

TProvider

Exceptions

JsonSerializationException

Thrown if deserialization or newline framing fails.

DeserializeEnumerableAsync<T, TProvider>(JsonSerializer, Stream, SequenceOptions, CancellationToken)

Asynchronously streams JSON values from a stream using the selected framing.

public static IAsyncEnumerable<T?> DeserializeEnumerableAsync<T, TProvider>(this JsonSerializer self, Stream stream, JsonSerializer.SequenceOptions options = default, CancellationToken cancellationToken = default)

Parameters

self JsonSerializer
stream Stream

The stream to read from. It is read but not disposed or closed by this method.

options JsonSerializer.SequenceOptions

The framing options. The default is newline-delimited JSON.

cancellationToken CancellationToken

A cancellation token.

Returns

IAsyncEnumerable<T>

An asynchronous sequence of values.

Type Parameters

T

The value type.

TProvider

DeserializePathEnumerableAsync<TElement>(JsonSerializer, PipeReader, JsonPath, MissingPathBehavior, CancellationToken)

Asynchronously streams the elements of a JSON array selected by a pre-parsed JsonPath inside an object or array envelope, parsing the preamble incrementally and draining the remainder of the envelope on completion.

public static IAsyncEnumerable<TElement?> DeserializePathEnumerableAsync<TElement>(this JsonSerializer self, PipeReader reader, JsonPath path, MissingPathBehavior missingBehavior = MissingPathBehavior.Throw, CancellationToken cancellationToken = default)

Parameters

self JsonSerializer
reader PipeReader

The pipe to read from. It is advanced but never completed by this method.

path JsonPath

The pre-parsed path that selects the array. Names are the serialized (wire) names.

missingBehavior MissingPathBehavior

Controls behavior when the path is not found.

cancellationToken CancellationToken

A cancellation token.

Returns

IAsyncEnumerable<TElement>

An asynchronous sequence of elements.

Type Parameters

TElement

The element type.

DeserializePathEnumerableAsync<TElement>(JsonSerializer, Stream, JsonPath, MissingPathBehavior, CancellationToken)

Asynchronously streams the elements of a JSON array selected by a pre-parsed JsonPath from a stream.

public static IAsyncEnumerable<TElement?> DeserializePathEnumerableAsync<TElement>(this JsonSerializer self, Stream stream, JsonPath path, MissingPathBehavior missingBehavior = MissingPathBehavior.Throw, CancellationToken cancellationToken = default)

Parameters

self JsonSerializer
stream Stream

The stream to read from. It is read but not disposed or closed by this method.

path JsonPath

The pre-parsed path that selects the array.

missingBehavior MissingPathBehavior

Controls behavior when the path is not found.

cancellationToken CancellationToken

A cancellation token.

Returns

IAsyncEnumerable<TElement>

An asynchronous sequence of elements.

Type Parameters

TElement

The element type.

DeserializePathEnumerableAsync<TElement, TProvider>(JsonSerializer, PipeReader, JsonPath, MissingPathBehavior, CancellationToken)

Asynchronously streams the elements of a JSON array selected by a pre-parsed JsonPath inside an object or array envelope, parsing the preamble incrementally and draining the remainder of the envelope on completion.

public static IAsyncEnumerable<TElement?> DeserializePathEnumerableAsync<TElement, TProvider>(this JsonSerializer self, PipeReader reader, JsonPath path, MissingPathBehavior missingBehavior = MissingPathBehavior.Throw, CancellationToken cancellationToken = default)

Parameters

self JsonSerializer
reader PipeReader

The pipe to read from. It is advanced but never completed by this method.

path JsonPath

The pre-parsed path that selects the array. Names are the serialized (wire) names.

missingBehavior MissingPathBehavior

Controls behavior when the path is not found.

cancellationToken CancellationToken

A cancellation token.

Returns

IAsyncEnumerable<TElement>

An asynchronous sequence of elements.

Type Parameters

TElement

The element type.

TProvider

DeserializePathEnumerableAsync<TRoot, TElement>(JsonSerializer, PipeReader, StreamingEnumerationOptions<TRoot, TElement>, CancellationToken)

Streams the array selected by a typed path, without buffering the enclosing document.

public static IAsyncEnumerable<TElement?> DeserializePathEnumerableAsync<TRoot, TElement>(this JsonSerializer self, PipeReader reader, JsonSerializer.StreamingEnumerationOptions<TRoot, TElement> options, CancellationToken cancellationToken = default)

Parameters

self JsonSerializer

The serializer.

reader PipeReader

The input pipe. options controls whether it is completed.

options JsonSerializer.StreamingEnumerationOptions<TRoot, TElement>

The path, missing-path behavior, and pipe ownership options.

cancellationToken CancellationToken

A cancellation token.

Returns

IAsyncEnumerable<TElement>

The selected array elements.

Type Parameters

TRoot

The root document type.

TElement

The selected array element type.

Remarks

Full enumeration drains the JSON envelope. Early disposal leaves the pipe at the last consumed token, not at a new JSON document.

DeserializePathEnumerableAsync<TElement, TProvider>(JsonSerializer, Stream, JsonPath, MissingPathBehavior, CancellationToken)

Asynchronously streams the elements of a JSON array selected by a pre-parsed JsonPath from a stream.

public static IAsyncEnumerable<TElement?> DeserializePathEnumerableAsync<TElement, TProvider>(this JsonSerializer self, Stream stream, JsonPath path, MissingPathBehavior missingBehavior = MissingPathBehavior.Throw, CancellationToken cancellationToken = default)

Parameters

self JsonSerializer
stream Stream

The stream to read from. It is read but not disposed or closed by this method.

path JsonPath

The pre-parsed path that selects the array.

missingBehavior MissingPathBehavior

Controls behavior when the path is not found.

cancellationToken CancellationToken

A cancellation token.

Returns

IAsyncEnumerable<TElement>

An asynchronous sequence of elements.

Type Parameters

TElement

The element type.

TProvider

DeserializePathEnumerableAsync<TRoot, TElement>(JsonSerializer, Stream, StreamingEnumerationOptions<TRoot, TElement>, CancellationToken)

Streams the array selected by a typed path, without buffering the enclosing document.

public static IAsyncEnumerable<TElement?> DeserializePathEnumerableAsync<TRoot, TElement>(this JsonSerializer self, Stream stream, JsonSerializer.StreamingEnumerationOptions<TRoot, TElement> options, CancellationToken cancellationToken = default)

Parameters

self JsonSerializer

The serializer.

stream Stream

The input stream, which remains open.

options JsonSerializer.StreamingEnumerationOptions<TRoot, TElement>

The path and enumeration options. The internally created pipe is always completed.

cancellationToken CancellationToken

A cancellation token.

Returns

IAsyncEnumerable<TElement>

The selected array elements.

Type Parameters

TRoot

The root document type.

TElement

The selected array element type.

Remarks

Full enumeration drains the JSON envelope. Early disposal leaves the pipe at the last consumed token, not at a new JSON document.

DeserializePathEnumerableAsync<TRoot, TElement, TProvider>(JsonSerializer, PipeReader, StreamingEnumerationOptions<TRoot, TElement>, CancellationToken)

Streams the array selected by a typed path, without buffering the enclosing document.

public static IAsyncEnumerable<TElement?> DeserializePathEnumerableAsync<TRoot, TElement, TProvider>(this JsonSerializer self, PipeReader reader, JsonSerializer.StreamingEnumerationOptions<TRoot, TElement> options, CancellationToken cancellationToken = default)

Parameters

self JsonSerializer

The serializer.

reader PipeReader

The input pipe. options controls whether it is completed.

options JsonSerializer.StreamingEnumerationOptions<TRoot, TElement>

The path, missing-path behavior, and pipe ownership options.

cancellationToken CancellationToken

A cancellation token.

Returns

IAsyncEnumerable<TElement>

The selected array elements.

Type Parameters

TRoot

The root document type.

TElement

The selected array element type.

TProvider

The root type shape witness.

Remarks

Full enumeration drains the JSON envelope. Early disposal leaves the pipe at the last consumed token, not at a new JSON document.

DeserializePathEnumerableAsync<TRoot, TElement, TProvider>(JsonSerializer, Stream, StreamingEnumerationOptions<TRoot, TElement>, CancellationToken)

Streams the array selected by a typed path, without buffering the enclosing document.

public static IAsyncEnumerable<TElement?> DeserializePathEnumerableAsync<TRoot, TElement, TProvider>(this JsonSerializer self, Stream stream, JsonSerializer.StreamingEnumerationOptions<TRoot, TElement> options, CancellationToken cancellationToken = default)

Parameters

self JsonSerializer

The serializer.

stream Stream

The input stream, which remains open.

options JsonSerializer.StreamingEnumerationOptions<TRoot, TElement>

The path and enumeration options. The internally created pipe is always completed.

cancellationToken CancellationToken

A cancellation token.

Returns

IAsyncEnumerable<TElement>

The selected array elements.

Type Parameters

TRoot

The root document type.

TElement

The selected array element type.

TProvider

The root type shape witness.

Remarks

Full enumeration drains the JSON envelope. Early disposal leaves the pipe at the last consumed token, not at a new JSON document.

DeserializePath<TValue>(JsonSerializer, ref JsonReader, JsonPath, MissingPathBehavior, CancellationToken)

Deserializes a raw JSON path from a reader.

public static TValue? DeserializePath<TValue>(this JsonSerializer self, ref JsonReader reader, JsonPath path, MissingPathBehavior missingBehavior = MissingPathBehavior.Throw, CancellationToken cancellationToken = default)

Parameters

self JsonSerializer
reader JsonReader

The reader positioned at the document.

path JsonPath

The raw path to select.

missingBehavior MissingPathBehavior

The behavior for a missing path.

cancellationToken CancellationToken

A cancellation token.

Returns

TValue

The selected value.

Type Parameters

TValue

The selected value type.

DeserializePath<TValue>(JsonSerializer, scoped in ReadOnlySequence<byte>, JsonPath, MissingPathBehavior, CancellationToken)

Deserializes only the value selected by a pre-parsed JsonPath from a possibly multi-segment UTF-8 buffer.

public static TValue? DeserializePath<TValue>(this JsonSerializer self, scoped in ReadOnlySequence<byte> utf8Json, JsonPath path, MissingPathBehavior missingBehavior = MissingPathBehavior.Throw, CancellationToken cancellationToken = default)

Parameters

self JsonSerializer
utf8Json ReadOnlySequence<byte>

The UTF-8 JSON document, possibly spanning multiple buffer segments.

path JsonPath

The pre-parsed path that selects the value.

missingBehavior MissingPathBehavior

Controls behavior when the path is not found.

cancellationToken CancellationToken

A cancellation token.

Returns

TValue

The deserialized value, or the default value when the path is missing and default behavior is selected.

Type Parameters

TValue

The type of the selected value.

DeserializePath<TValue>(JsonSerializer, Stream, JsonPath, MissingPathBehavior, CancellationToken)

Deserializes a raw JSON path from a stream.

public static TValue? DeserializePath<TValue>(this JsonSerializer self, Stream stream, JsonPath path, MissingPathBehavior missingBehavior = MissingPathBehavior.Throw, CancellationToken cancellationToken = default)

Parameters

self JsonSerializer
stream Stream

The document stream, which is read to its end and remains open.

path JsonPath

The raw JSON path.

missingBehavior MissingPathBehavior

The behavior for a missing path.

cancellationToken CancellationToken

A cancellation token.

Returns

TValue

The selected value.

Type Parameters

TValue

The selected value type.

DeserializePath<TValue>(JsonSerializer, ReadOnlyMemory<byte>, JsonPath, MissingPathBehavior, CancellationToken)

Deserializes only the value selected by a pre-parsed JsonPath from a UTF-8 buffer.

public static TValue? DeserializePath<TValue>(this JsonSerializer self, ReadOnlyMemory<byte> utf8Json, JsonPath path, MissingPathBehavior missingBehavior = MissingPathBehavior.Throw, CancellationToken cancellationToken = default)

Parameters

self JsonSerializer
utf8Json ReadOnlyMemory<byte>

The UTF-8 JSON document.

path JsonPath

The pre-parsed path that selects the value.

missingBehavior MissingPathBehavior

Controls behavior when the path is not found.

cancellationToken CancellationToken

A cancellation token.

Returns

TValue

The deserialized value, or the default value when the path is missing and default behavior is selected.

Type Parameters

TValue

The type of the selected value.

DeserializePath<TValue>(JsonSerializer, string, JsonPath, MissingPathBehavior, CancellationToken)

Deserializes only the value selected by a pre-parsed JsonPath, skipping unrelated JSON.

public static TValue? DeserializePath<TValue>(this JsonSerializer self, string json, JsonPath path, MissingPathBehavior missingBehavior = MissingPathBehavior.Throw, CancellationToken cancellationToken = default)

Parameters

self JsonSerializer
json string

The JSON document.

path JsonPath

The pre-parsed path that selects the value.

missingBehavior MissingPathBehavior

Controls behavior when the path is not found.

cancellationToken CancellationToken

A cancellation token.

Returns

TValue

The deserialized value, or the default value if the path is missing and missingBehavior is ReturnDefault.

Type Parameters

TValue

The type of the selected value.

Remarks

The selected value is deserialized through the full converter graph, so naming policies, custom converters, and union envelopes remain correct for the target. Path segments navigate plain JSON objects and arrays; targeted deserialization is not supported when reference preservation is enabled.

DeserializePath<TValue, TProvider>(JsonSerializer, ref JsonReader, JsonPath, MissingPathBehavior, CancellationToken)

Deserializes a raw JSON path from a reader.

public static TValue? DeserializePath<TValue, TProvider>(this JsonSerializer self, ref JsonReader reader, JsonPath path, MissingPathBehavior missingBehavior = MissingPathBehavior.Throw, CancellationToken cancellationToken = default)

Parameters

self JsonSerializer
reader JsonReader

The reader positioned at the document.

path JsonPath

The raw path to select.

missingBehavior MissingPathBehavior

The behavior for a missing path.

cancellationToken CancellationToken

A cancellation token.

Returns

TValue

The selected value.

Type Parameters

TValue

The selected value type.

TProvider

DeserializePath<TRoot, TElement>(JsonSerializer, ref JsonReader, in DeserializePathOptions<TRoot, TElement>, CancellationToken)

Deserializes a value selected by an expression, leaving the reader immediately after that value.

public static TElement? DeserializePath<TRoot, TElement>(this JsonSerializer self, ref JsonReader reader, in JsonSerializer.DeserializePathOptions<TRoot, TElement> options, CancellationToken cancellationToken = default)

Parameters

self JsonSerializer

The serializer.

reader JsonReader

The reader positioned at the root document.

options JsonSerializer.DeserializePathOptions<TRoot, TElement>

The selection options.

cancellationToken CancellationToken

A cancellation token.

Returns

TElement

The selected value.

Type Parameters

TRoot

The root document type.

TElement

The selected value type.

DeserializePath<TValue, TProvider>(JsonSerializer, scoped in ReadOnlySequence<byte>, JsonPath, MissingPathBehavior, CancellationToken)

Deserializes only the value selected by a pre-parsed JsonPath from a possibly multi-segment UTF-8 buffer.

public static TValue? DeserializePath<TValue, TProvider>(this JsonSerializer self, scoped in ReadOnlySequence<byte> utf8Json, JsonPath path, MissingPathBehavior missingBehavior = MissingPathBehavior.Throw, CancellationToken cancellationToken = default)

Parameters

self JsonSerializer
utf8Json ReadOnlySequence<byte>

The UTF-8 JSON document, possibly spanning multiple buffer segments.

path JsonPath

The pre-parsed path that selects the value.

missingBehavior MissingPathBehavior

Controls behavior when the path is not found.

cancellationToken CancellationToken

A cancellation token.

Returns

TValue

The deserialized value, or the default value when the path is missing and default behavior is selected.

Type Parameters

TValue

The type of the selected value.

TProvider

DeserializePath<TRoot, TElement>(JsonSerializer, scoped in ReadOnlySequence<byte>, in DeserializePathOptions<TRoot, TElement>, CancellationToken)

Deserializes a value selected by an expression, leaving the reader immediately after that value.

public static TElement? DeserializePath<TRoot, TElement>(this JsonSerializer self, scoped in ReadOnlySequence<byte> utf8Json, in JsonSerializer.DeserializePathOptions<TRoot, TElement> options, CancellationToken cancellationToken = default)

Parameters

self JsonSerializer

The serializer.

utf8Json ReadOnlySequence<byte>

The possibly segmented UTF-8 document.

options JsonSerializer.DeserializePathOptions<TRoot, TElement>

The selection options.

cancellationToken CancellationToken

A cancellation token.

Returns

TElement

The selected value.

Type Parameters

TRoot

The root document type.

TElement

The selected value type.

DeserializePath<TValue, TProvider>(JsonSerializer, Stream, JsonPath, MissingPathBehavior, CancellationToken)

Deserializes a raw JSON path from a stream.

public static TValue? DeserializePath<TValue, TProvider>(this JsonSerializer self, Stream stream, JsonPath path, MissingPathBehavior missingBehavior = MissingPathBehavior.Throw, CancellationToken cancellationToken = default)

Parameters

self JsonSerializer
stream Stream

The document stream, which is read to its end and remains open.

path JsonPath

The raw JSON path.

missingBehavior MissingPathBehavior

The behavior for a missing path.

cancellationToken CancellationToken

A cancellation token.

Returns

TValue

The selected value.

Type Parameters

TValue

The selected value type.

TProvider

DeserializePath<TRoot, TElement>(JsonSerializer, Stream, in DeserializePathOptions<TRoot, TElement>, CancellationToken)

Deserializes a value selected by an expression, leaving the reader immediately after that value.

public static TElement? DeserializePath<TRoot, TElement>(this JsonSerializer self, Stream stream, in JsonSerializer.DeserializePathOptions<TRoot, TElement> options, CancellationToken cancellationToken = default)

Parameters

self JsonSerializer

The serializer.

stream Stream

The document stream, which is read to its end and remains open.

options JsonSerializer.DeserializePathOptions<TRoot, TElement>

The selection options.

cancellationToken CancellationToken

A cancellation token.

Returns

TElement

The selected value.

Type Parameters

TRoot

The root document type.

TElement

The selected value type.

DeserializePath<TValue, TProvider>(JsonSerializer, ReadOnlyMemory<byte>, JsonPath, MissingPathBehavior, CancellationToken)

Deserializes only the value selected by a pre-parsed JsonPath from a UTF-8 buffer.

public static TValue? DeserializePath<TValue, TProvider>(this JsonSerializer self, ReadOnlyMemory<byte> utf8Json, JsonPath path, MissingPathBehavior missingBehavior = MissingPathBehavior.Throw, CancellationToken cancellationToken = default)

Parameters

self JsonSerializer
utf8Json ReadOnlyMemory<byte>

The UTF-8 JSON document.

path JsonPath

The pre-parsed path that selects the value.

missingBehavior MissingPathBehavior

Controls behavior when the path is not found.

cancellationToken CancellationToken

A cancellation token.

Returns

TValue

The deserialized value, or the default value when the path is missing and default behavior is selected.

Type Parameters

TValue

The type of the selected value.

TProvider

DeserializePath<TRoot, TElement>(JsonSerializer, ReadOnlyMemory<byte>, in DeserializePathOptions<TRoot, TElement>, CancellationToken)

Deserializes a value selected by an expression, leaving the reader immediately after that value.

public static TElement? DeserializePath<TRoot, TElement>(this JsonSerializer self, ReadOnlyMemory<byte> utf8Json, in JsonSerializer.DeserializePathOptions<TRoot, TElement> options, CancellationToken cancellationToken = default)

Parameters

self JsonSerializer

The serializer.

utf8Json ReadOnlyMemory<byte>

The UTF-8 document.

options JsonSerializer.DeserializePathOptions<TRoot, TElement>

The selection options.

cancellationToken CancellationToken

A cancellation token.

Returns

TElement

The selected value.

Type Parameters

TRoot

The root document type.

TElement

The selected value type.

DeserializePath<TValue, TProvider>(JsonSerializer, string, JsonPath, MissingPathBehavior, CancellationToken)

Deserializes only the value selected by a pre-parsed JsonPath, skipping unrelated JSON.

public static TValue? DeserializePath<TValue, TProvider>(this JsonSerializer self, string json, JsonPath path, MissingPathBehavior missingBehavior = MissingPathBehavior.Throw, CancellationToken cancellationToken = default)

Parameters

self JsonSerializer
json string

The JSON document.

path JsonPath

The pre-parsed path that selects the value.

missingBehavior MissingPathBehavior

Controls behavior when the path is not found.

cancellationToken CancellationToken

A cancellation token.

Returns

TValue

The deserialized value, or the default value if the path is missing and missingBehavior is ReturnDefault.

Type Parameters

TValue

The type of the selected value.

TProvider

Remarks

The selected value is deserialized through the full converter graph, so naming policies, custom converters, and union envelopes remain correct for the target. Path segments navigate plain JSON objects and arrays; targeted deserialization is not supported when reference preservation is enabled.

DeserializePath<TRoot, TElement>(JsonSerializer, string, in DeserializePathOptions<TRoot, TElement>, CancellationToken)

Deserializes a value selected by an expression, leaving the reader immediately after that value.

public static TElement? DeserializePath<TRoot, TElement>(this JsonSerializer self, string json, in JsonSerializer.DeserializePathOptions<TRoot, TElement> options, CancellationToken cancellationToken = default)

Parameters

self JsonSerializer

The serializer.

json string

The JSON document.

options JsonSerializer.DeserializePathOptions<TRoot, TElement>

The selection options.

cancellationToken CancellationToken

A cancellation token.

Returns

TElement

The selected value.

Type Parameters

TRoot

The root document type.

TElement

The selected value type.

DeserializePath<TRoot, TElement, TProvider>(JsonSerializer, ref JsonReader, in DeserializePathOptions<TRoot, TElement>, CancellationToken)

Deserializes a value selected by an expression, leaving the reader immediately after that value.

public static TElement? DeserializePath<TRoot, TElement, TProvider>(this JsonSerializer self, ref JsonReader reader, in JsonSerializer.DeserializePathOptions<TRoot, TElement> options, CancellationToken cancellationToken = default)

Parameters

self JsonSerializer

The serializer.

reader JsonReader

The reader positioned at the root document.

options JsonSerializer.DeserializePathOptions<TRoot, TElement>

The selection options.

cancellationToken CancellationToken

A cancellation token.

Returns

TElement

The selected value.

Type Parameters

TRoot

The root document type.

TElement

The selected value type.

TProvider

The root type shape witness.

DeserializePath<TRoot, TElement, TProvider>(JsonSerializer, scoped in ReadOnlySequence<byte>, in DeserializePathOptions<TRoot, TElement>, CancellationToken)

Deserializes a value selected by an expression, leaving the reader immediately after that value.

public static TElement? DeserializePath<TRoot, TElement, TProvider>(this JsonSerializer self, scoped in ReadOnlySequence<byte> utf8Json, in JsonSerializer.DeserializePathOptions<TRoot, TElement> options, CancellationToken cancellationToken = default)

Parameters

self JsonSerializer

The serializer.

utf8Json ReadOnlySequence<byte>

The possibly segmented UTF-8 document.

options JsonSerializer.DeserializePathOptions<TRoot, TElement>

The selection options.

cancellationToken CancellationToken

A cancellation token.

Returns

TElement

The selected value.

Type Parameters

TRoot

The root document type.

TElement

The selected value type.

TProvider

The root type shape witness.

DeserializePath<TRoot, TElement, TProvider>(JsonSerializer, Stream, in DeserializePathOptions<TRoot, TElement>, CancellationToken)

Deserializes a value selected by an expression, leaving the reader immediately after that value.

public static TElement? DeserializePath<TRoot, TElement, TProvider>(this JsonSerializer self, Stream stream, in JsonSerializer.DeserializePathOptions<TRoot, TElement> options, CancellationToken cancellationToken = default)

Parameters

self JsonSerializer

The serializer.

stream Stream

The document stream, which is read to its end and remains open.

options JsonSerializer.DeserializePathOptions<TRoot, TElement>

The selection options.

cancellationToken CancellationToken

A cancellation token.

Returns

TElement

The selected value.

Type Parameters

TRoot

The root document type.

TElement

The selected value type.

TProvider

The root type shape witness.

DeserializePath<TRoot, TElement, TProvider>(JsonSerializer, ReadOnlyMemory<byte>, in DeserializePathOptions<TRoot, TElement>, CancellationToken)

Deserializes a value selected by an expression, leaving the reader immediately after that value.

public static TElement? DeserializePath<TRoot, TElement, TProvider>(this JsonSerializer self, ReadOnlyMemory<byte> utf8Json, in JsonSerializer.DeserializePathOptions<TRoot, TElement> options, CancellationToken cancellationToken = default)

Parameters

self JsonSerializer

The serializer.

utf8Json ReadOnlyMemory<byte>

The UTF-8 document.

options JsonSerializer.DeserializePathOptions<TRoot, TElement>

The selection options.

cancellationToken CancellationToken

A cancellation token.

Returns

TElement

The selected value.

Type Parameters

TRoot

The root document type.

TElement

The selected value type.

TProvider

The root type shape witness.

DeserializePath<TRoot, TElement, TProvider>(JsonSerializer, string, in DeserializePathOptions<TRoot, TElement>, CancellationToken)

Deserializes a value selected by an expression, leaving the reader immediately after that value.

public static TElement? DeserializePath<TRoot, TElement, TProvider>(this JsonSerializer self, string json, in JsonSerializer.DeserializePathOptions<TRoot, TElement> options, CancellationToken cancellationToken = default)

Parameters

self JsonSerializer

The serializer.

json string

The JSON document.

options JsonSerializer.DeserializePathOptions<TRoot, TElement>

The selection options.

cancellationToken CancellationToken

A cancellation token.

Returns

TElement

The selected value.

Type Parameters

TRoot

The root document type.

TElement

The selected value type.

TProvider

The root type shape witness.

SerializeEnumerableAsync<T>(JsonSerializer, PipeWriter, IAsyncEnumerable<T>, SequenceOptions, CancellationToken)

Asynchronously serializes an IAsyncEnumerable<T> using the selected JSON framing.

public static ValueTask SerializeEnumerableAsync<T>(this JsonSerializer self, PipeWriter writer, IAsyncEnumerable<T> values, JsonSerializer.SequenceOptions options = default, CancellationToken cancellationToken = default)

Parameters

self JsonSerializer
writer PipeWriter

The pipe to write to. It is flushed but never completed by this method.

values IAsyncEnumerable<T>

The asynchronous source of values.

options JsonSerializer.SequenceOptions

The framing options. The default is newline-delimited JSON.

cancellationToken CancellationToken

A cancellation token.

Returns

ValueTask

A task tracking the serialization.

Type Parameters

T

The value type.

SerializeEnumerableAsync<T>(JsonSerializer, Stream, IAsyncEnumerable<T>, SequenceOptions, CancellationToken)

Asynchronously serializes an IAsyncEnumerable<T> to a stream using the selected JSON framing.

public static ValueTask SerializeEnumerableAsync<T>(this JsonSerializer self, Stream stream, IAsyncEnumerable<T> values, JsonSerializer.SequenceOptions options = default, CancellationToken cancellationToken = default)

Parameters

self JsonSerializer
stream Stream

The stream to write to. It is flushed but not disposed or closed by this method.

values IAsyncEnumerable<T>

The asynchronous source of values.

options JsonSerializer.SequenceOptions

The framing options. The default is newline-delimited JSON.

cancellationToken CancellationToken

A cancellation token.

Returns

ValueTask

A task tracking the serialization.

Type Parameters

T

The value type.

SerializeEnumerableAsync<T, TProvider>(JsonSerializer, PipeWriter, IAsyncEnumerable<T>, SequenceOptions, CancellationToken)

Asynchronously serializes an IAsyncEnumerable<T> using the selected JSON framing.

public static ValueTask SerializeEnumerableAsync<T, TProvider>(this JsonSerializer self, PipeWriter writer, IAsyncEnumerable<T> values, JsonSerializer.SequenceOptions options = default, CancellationToken cancellationToken = default)

Parameters

self JsonSerializer
writer PipeWriter

The pipe to write to. It is flushed but never completed by this method.

values IAsyncEnumerable<T>

The asynchronous source of values.

options JsonSerializer.SequenceOptions

The framing options. The default is newline-delimited JSON.

cancellationToken CancellationToken

A cancellation token.

Returns

ValueTask

A task tracking the serialization.

Type Parameters

T

The value type.

TProvider

SerializeEnumerableAsync<T, TProvider>(JsonSerializer, Stream, IAsyncEnumerable<T>, SequenceOptions, CancellationToken)

Asynchronously serializes an IAsyncEnumerable<T> to a stream using the selected JSON framing.

public static ValueTask SerializeEnumerableAsync<T, TProvider>(this JsonSerializer self, Stream stream, IAsyncEnumerable<T> values, JsonSerializer.SequenceOptions options = default, CancellationToken cancellationToken = default)

Parameters

self JsonSerializer
stream Stream

The stream to write to. It is flushed but not disposed or closed by this method.

values IAsyncEnumerable<T>

The asynchronous source of values.

options JsonSerializer.SequenceOptions

The framing options. The default is newline-delimited JSON.

cancellationToken CancellationToken

A cancellation token.

Returns

ValueTask

A task tracking the serialization.

Type Parameters

T

The value type.

TProvider