<PackageReference Include="System.Text.Json" Version="7.0.2" />

JsonSerializer

public static class JsonSerializer
Provides functionality to serialize objects or value types to JSON and to deserialize JSON into objects or value types.
public static TValue Deserialize<TValue>(this JsonDocument document, JsonSerializerOptions options = null)

Converts the JsonDocument representing a single JSON value into a TValue.

public static object Deserialize(this JsonDocument document, Type returnType, JsonSerializerOptions options = null)

Converts the JsonDocument representing a single JSON value into a returnType.

public static TValue Deserialize<TValue>(this JsonDocument document, JsonTypeInfo<TValue> jsonTypeInfo)

Converts the JsonDocument representing a single JSON value into a TValue.

public static object Deserialize(this JsonDocument document, Type returnType, JsonSerializerContext context)

Converts the JsonDocument representing a single JSON value into a returnType.

public static TValue Deserialize<TValue>(this JsonElement element, JsonSerializerOptions options = null)

Converts the JsonElement representing a single JSON value into a TValue.

public static object Deserialize(this JsonElement element, Type returnType, JsonSerializerOptions options = null)

Converts the JsonElement representing a single JSON value into a returnType.

public static TValue Deserialize<TValue>(this JsonElement element, JsonTypeInfo<TValue> jsonTypeInfo)

Converts the JsonElement representing a single JSON value into a TValue.

public static object Deserialize(this JsonElement element, Type returnType, JsonSerializerContext context)

Converts the JsonElement representing a single JSON value into a returnType.

public static TValue Deserialize<TValue>(this JsonNode node, JsonSerializerOptions options = null)

Converts the JsonNode representing a single JSON value into a TValue.

public static object Deserialize(this JsonNode node, Type returnType, JsonSerializerOptions options = null)

Converts the JsonNode representing a single JSON value into a returnType.

public static TValue Deserialize<TValue>(this JsonNode node, JsonTypeInfo<TValue> jsonTypeInfo)

Converts the JsonNode representing a single JSON value into a TValue.

public static object Deserialize(this JsonNode node, Type returnType, JsonSerializerContext context)

Converts the JsonNode representing a single JSON value into a returnType.

public static TValue Deserialize<TValue>(ReadOnlySpan<byte> utf8Json, JsonSerializerOptions options = null)

Parses the UTF-8 encoded text representing a single JSON value into an instance of the type specified by a generic type parameter.

public static object Deserialize(ReadOnlySpan<byte> utf8Json, Type returnType, JsonSerializerOptions options = null)

Parses the UTF-8 encoded text representing a single JSON value into an instance of a specified type.

public static TValue Deserialize<TValue>(ReadOnlySpan<byte> utf8Json, JsonTypeInfo<TValue> jsonTypeInfo)

Parses the UTF-8 encoded text representing a single JSON value into a TValue.

public static object Deserialize(ReadOnlySpan<byte> utf8Json, Type returnType, JsonSerializerContext context)

Parses the UTF-8 encoded text representing a single JSON value into a returnType.

public static TValue Deserialize<TValue>(Stream utf8Json, JsonSerializerOptions options = null)

Reads the UTF-8 encoded text representing a single JSON value into a TValue. The Stream will be read to completion.

public static object Deserialize(Stream utf8Json, Type returnType, JsonSerializerOptions options = null)

Reads the UTF-8 encoded text representing a single JSON value into a returnType. The Stream will be read to completion.

public static TValue Deserialize<TValue>(Stream utf8Json, JsonTypeInfo<TValue> jsonTypeInfo)

Reads the UTF-8 encoded text representing a single JSON value into a TValue. The Stream will be read to completion.

public static object Deserialize(Stream utf8Json, Type returnType, JsonSerializerContext context)

Reads the UTF-8 encoded text representing a single JSON value into a returnType. The Stream will be read to completion.

public static TValue Deserialize<TValue>(string json, JsonSerializerOptions options = null)

Parses the text representing a single JSON value into an instance of the type specified by a generic type parameter.

public static TValue Deserialize<TValue>(ReadOnlySpan<char> json, JsonSerializerOptions options = null)

Parses the text representing a single JSON value into an instance of the type specified by a generic type parameter.

public static object Deserialize(string json, Type returnType, JsonSerializerOptions options = null)

Parses the text representing a single JSON value into an instance of a specified type.

public static object Deserialize(ReadOnlySpan<char> json, Type returnType, JsonSerializerOptions options = null)

Parses the text representing a single JSON value into an instance of a specified type.

public static TValue Deserialize<TValue>(string json, JsonTypeInfo<TValue> jsonTypeInfo)

Parses the text representing a single JSON value into a TValue.

public static TValue Deserialize<TValue>(ReadOnlySpan<char> json, JsonTypeInfo<TValue> jsonTypeInfo)

Parses the text representing a single JSON value into a TValue.

public static object Deserialize(string json, Type returnType, JsonSerializerContext context)

Parses the text representing a single JSON value into a returnType.

public static object Deserialize(ReadOnlySpan<char> json, Type returnType, JsonSerializerContext context)

Parses the text representing a single JSON value into a returnType.

public static TValue Deserialize<TValue>(ref Utf8JsonReader reader, JsonSerializerOptions options = null)

Reads one JSON value (including objects or arrays) from the provided reader into an instance of the type specified by a generic type parameter.

public static object Deserialize(ref Utf8JsonReader reader, Type returnType, JsonSerializerOptions options = null)

Reads one JSON value (including objects or arrays) from the provided reader and converts it into an instance of a specified type.

public static TValue Deserialize<TValue>(ref Utf8JsonReader reader, JsonTypeInfo<TValue> jsonTypeInfo)

Reads one JSON value (including objects or arrays) from the provided reader into a TValue.

public static object Deserialize(ref Utf8JsonReader reader, Type returnType, JsonSerializerContext context)

Reads one JSON value (including objects or arrays) from the provided reader into a returnType.

public static ValueTask<TValue> DeserializeAsync<TValue>(Stream utf8Json, JsonSerializerOptions options = null, CancellationToken cancellationToken = default)

Asynchronously reads the UTF-8 encoded text representing a single JSON value into an instance of a type specified by a generic type parameter. The stream will be read to completion.

public static ValueTask<object> DeserializeAsync(Stream utf8Json, Type returnType, JsonSerializerOptions options = null, CancellationToken cancellationToken = default)

Asynchronously reads the UTF-8 encoded text representing a single JSON value into an instance of a specified type. The stream will be read to completion.

public static ValueTask<TValue> DeserializeAsync<TValue>(Stream utf8Json, JsonTypeInfo<TValue> jsonTypeInfo, CancellationToken cancellationToken = default)

Reads the UTF-8 encoded text representing a single JSON value into a TValue. The Stream will be read to completion.

public static ValueTask<object> DeserializeAsync(Stream utf8Json, Type returnType, JsonSerializerContext context, CancellationToken cancellationToken = default)

Reads the UTF-8 encoded text representing a single JSON value into a returnType. The Stream will be read to completion.

public static IAsyncEnumerable<TValue> DeserializeAsyncEnumerable<TValue>(Stream utf8Json, JsonSerializerOptions options = null, CancellationToken cancellationToken = default)

Wraps the UTF-8 encoded text into an IAsyncEnumerable<T> that can be used to deserialize root-level JSON arrays in a streaming manner.

public static IAsyncEnumerable<TValue> DeserializeAsyncEnumerable<TValue>(Stream utf8Json, JsonTypeInfo<TValue> jsonTypeInfo, CancellationToken cancellationToken = default)

Wraps the UTF-8 encoded text into an IAsyncEnumerable<T> that can be used to deserialize root-level JSON arrays in a streaming manner.

public static void Serialize<TValue>(Stream utf8Json, TValue value, JsonSerializerOptions options = null)

Converts the provided value to UTF-8 encoded JSON text and write it to the Stream.

public static void Serialize(Stream utf8Json, object value, Type inputType, JsonSerializerOptions options = null)

Converts the provided value to UTF-8 encoded JSON text and write it to the Stream.

public static void Serialize<TValue>(Stream utf8Json, TValue value, JsonTypeInfo<TValue> jsonTypeInfo)

Converts the provided value to UTF-8 encoded JSON text and write it to the Stream.

public static void Serialize(Stream utf8Json, object value, Type inputType, JsonSerializerContext context)

Converts the provided value to UTF-8 encoded JSON text and write it to the Stream.

public static string Serialize<TValue>(TValue value, JsonSerializerOptions options = null)

Converts the value of a type specified by a generic type parameter into a JSON string.

public static string Serialize(object value, Type inputType, JsonSerializerOptions options = null)

Converts the value of a specified type into a JSON string.

public static string Serialize<TValue>(TValue value, JsonTypeInfo<TValue> jsonTypeInfo)

Converts the provided value into a String.

public static string Serialize(object value, Type inputType, JsonSerializerContext context)

Converts the provided value into a String.

public static void Serialize<TValue>(Utf8JsonWriter writer, TValue value, JsonSerializerOptions options = null)

Writes the JSON representation of a type specified by a generic type parameter to the provided writer.

public static void Serialize(Utf8JsonWriter writer, object value, Type inputType, JsonSerializerOptions options = null)

Writes the JSON representation of the specified type to the provided writer.

public static void Serialize<TValue>(Utf8JsonWriter writer, TValue value, JsonTypeInfo<TValue> jsonTypeInfo)

Writes one JSON value (including objects or arrays) to the provided writer.

public static void Serialize(Utf8JsonWriter writer, object value, Type inputType, JsonSerializerContext context)

Writes one JSON value (including objects or arrays) to the provided writer.

public static Task SerializeAsync<TValue>(Stream utf8Json, TValue value, JsonSerializerOptions options = null, CancellationToken cancellationToken = default)

Asynchronously converts a value of a type specified by a generic type parameter to UTF-8 encoded JSON text and writes it to a stream.

public static Task SerializeAsync(Stream utf8Json, object value, Type inputType, JsonSerializerOptions options = null, CancellationToken cancellationToken = default)

Asynchronously converts the value of a specified type to UTF-8 encoded JSON text and writes it to the specified stream.

public static Task SerializeAsync<TValue>(Stream utf8Json, TValue value, JsonTypeInfo<TValue> jsonTypeInfo, CancellationToken cancellationToken = default)

Converts the provided value to UTF-8 encoded JSON text and write it to the Stream.

public static Task SerializeAsync(Stream utf8Json, object value, Type inputType, JsonSerializerContext context, CancellationToken cancellationToken = default)

Converts the provided value to UTF-8 encoded JSON text and write it to the Stream.

public static JsonDocument SerializeToDocument<TValue>(TValue value, JsonSerializerOptions options = null)

Converts the provided value into a JsonDocument.

public static JsonDocument SerializeToDocument(object value, Type inputType, JsonSerializerOptions options = null)

Converts the provided value into a JsonDocument.

public static JsonDocument SerializeToDocument<TValue>(TValue value, JsonTypeInfo<TValue> jsonTypeInfo)

Converts the provided value into a JsonDocument.

public static JsonDocument SerializeToDocument(object value, Type inputType, JsonSerializerContext context)

Converts the provided value into a JsonDocument.

public static JsonElement SerializeToElement<TValue>(TValue value, JsonSerializerOptions options = null)

Converts the provided value into a JsonDocument.

public static JsonElement SerializeToElement(object value, Type inputType, JsonSerializerOptions options = null)

Converts the provided value into a JsonDocument.

public static JsonElement SerializeToElement<TValue>(TValue value, JsonTypeInfo<TValue> jsonTypeInfo)

Converts the provided value into a JsonDocument.

public static JsonElement SerializeToElement(object value, Type inputType, JsonSerializerContext context)

Converts the provided value into a JsonDocument.

public static JsonNode SerializeToNode<TValue>(TValue value, JsonSerializerOptions options = null)

Converts the provided value into a JsonNode.

public static JsonNode SerializeToNode(object value, Type inputType, JsonSerializerOptions options = null)

Converts the provided value into a JsonNode.

public static JsonNode SerializeToNode<TValue>(TValue value, JsonTypeInfo<TValue> jsonTypeInfo)

Converts the provided value into a JsonNode.

public static JsonNode SerializeToNode(object value, Type inputType, JsonSerializerContext context)

Converts the provided value into a JsonNode.

public static byte[] SerializeToUtf8Bytes<TValue>(TValue value, JsonSerializerOptions options = null)

Converts the value of a type specified by a generic type parameter into a JSON string, encoded as UTF-8 bytes.

public static byte[] SerializeToUtf8Bytes(object value, Type inputType, JsonSerializerOptions options = null)

Converts a value of the specified type into a JSON string, encoded as UTF-8 bytes.

public static byte[] SerializeToUtf8Bytes<TValue>(TValue value, JsonTypeInfo<TValue> jsonTypeInfo)

Converts the provided value into a Byte array.

public static byte[] SerializeToUtf8Bytes(object value, Type inputType, JsonSerializerContext context)

Converts the provided value into a Byte array.