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>(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.
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 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 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.
Converts the value of a type specified by a generic type parameter into a JSON string.
Converts the value of a specified type into a JSON 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 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 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.