HttpResponseJsonExtensions.WriteAsJsonAsync Method

Definition

Overloads

WriteAsJsonAsync(HttpResponse, Object, Type, CancellationToken)

Write the specified value as JSON to the response body. The response content-type will be set to application/json; charset=utf-8.

WriteAsJsonAsync(HttpResponse, Object, JsonTypeInfo, String, CancellationToken)

Write the specified value as JSON to the response body. The response content-type will be set to the specified content-type.

WriteAsJsonAsync(HttpResponse, Object, Type, JsonSerializerOptions, CancellationToken)

Write the specified value as JSON to the response body. The response content-type will be set to application/json; charset=utf-8.

WriteAsJsonAsync(HttpResponse, Object, Type, JsonSerializerOptions, String, CancellationToken)

Write the specified value as JSON to the response body. The response content-type will be set to the specified content-type.

WriteAsJsonAsync(HttpResponse, Object, Type, JsonSerializerContext, String, CancellationToken)

Write the specified value as JSON to the response body. The response content-type will be set to the specified content-type.

WriteAsJsonAsync<TValue>(HttpResponse, TValue, CancellationToken)

Write the specified value as JSON to the response body. The response content-type will be set to application/json; charset=utf-8.

WriteAsJsonAsync<TValue>(HttpResponse, TValue, JsonSerializerOptions, CancellationToken)

Write the specified value as JSON to the response body. The response content-type will be set to application/json; charset=utf-8.

WriteAsJsonAsync<TValue>(HttpResponse, TValue, JsonSerializerOptions, String, CancellationToken)

Write the specified value as JSON to the response body. The response content-type will be set to the specified content-type.

WriteAsJsonAsync<TValue>(HttpResponse, TValue, JsonTypeInfo<TValue>, String, CancellationToken)

Write the specified value as JSON to the response body. The response content-type will be set to the specified content-type.

WriteAsJsonAsync(HttpResponse, Object, Type, CancellationToken)

Source:
HttpResponseJsonExtensions.cs

Write the specified value as JSON to the response body. The response content-type will be set to application/json; charset=utf-8.

C#
public static System.Threading.Tasks.Task WriteAsJsonAsync (this Microsoft.AspNetCore.Http.HttpResponse response, object? value, Type type, System.Threading.CancellationToken cancellationToken = default);

Parameters

response
HttpResponse

The response to write JSON to.

value
Object

The value to write as JSON.

type
Type

The type of object to write.

cancellationToken
CancellationToken

A CancellationToken used to cancel the operation.

Returns

The task object representing the asynchronous operation.

Applies to

ASP.NET Core 9.0 and other versions
Product Versions
ASP.NET Core 5.0, 6.0, 7.0, 8.0, 9.0

WriteAsJsonAsync(HttpResponse, Object, JsonTypeInfo, String, CancellationToken)

Source:
HttpResponseJsonExtensions.cs

Write the specified value as JSON to the response body. The response content-type will be set to the specified content-type.

C#
public static System.Threading.Tasks.Task WriteAsJsonAsync (this Microsoft.AspNetCore.Http.HttpResponse response, object? value, System.Text.Json.Serialization.Metadata.JsonTypeInfo jsonTypeInfo, string? contentType = default, System.Threading.CancellationToken cancellationToken = default);

Parameters

response
HttpResponse

The response to write JSON to.

value
Object

The value to write as JSON.

jsonTypeInfo
JsonTypeInfo

Metadata about the type to convert.

contentType
String

The content-type to set on the response.

cancellationToken
CancellationToken

A CancellationToken used to cancel the operation.

Returns

The task object representing the asynchronous operation.

Applies to

ASP.NET Core 9.0 and ASP.NET Core 8.0
Product Versions
ASP.NET Core 8.0, 9.0

WriteAsJsonAsync(HttpResponse, Object, Type, JsonSerializerOptions, CancellationToken)

Source:
HttpResponseJsonExtensions.cs

Write the specified value as JSON to the response body. The response content-type will be set to application/json; charset=utf-8.

C#
public static System.Threading.Tasks.Task WriteAsJsonAsync (this Microsoft.AspNetCore.Http.HttpResponse response, object? value, Type type, System.Text.Json.JsonSerializerOptions? options, System.Threading.CancellationToken cancellationToken = default);

Parameters

response
HttpResponse

The response to write JSON to.

value
Object

The value to write as JSON.

type
Type

The type of object to write.

options
JsonSerializerOptions

The serializer options to use when serializing the value.

cancellationToken
CancellationToken

A CancellationToken used to cancel the operation.

Returns

The task object representing the asynchronous operation.

Applies to

ASP.NET Core 9.0 and other versions
Product Versions
ASP.NET Core 5.0, 6.0, 7.0, 8.0, 9.0

WriteAsJsonAsync(HttpResponse, Object, Type, JsonSerializerOptions, String, CancellationToken)

Source:
HttpResponseJsonExtensions.cs

Write the specified value as JSON to the response body. The response content-type will be set to the specified content-type.

C#
public static System.Threading.Tasks.Task WriteAsJsonAsync (this Microsoft.AspNetCore.Http.HttpResponse response, object? value, Type type, System.Text.Json.JsonSerializerOptions? options, string? contentType, System.Threading.CancellationToken cancellationToken = default);

Parameters

response
HttpResponse

The response to write JSON to.

value
Object

The value to write as JSON.

type
Type

The type of object to write.

options
JsonSerializerOptions

The serializer options to use when serializing the value.

contentType
String

The content-type to set on the response.

cancellationToken
CancellationToken

A CancellationToken used to cancel the operation.

Returns

The task object representing the asynchronous operation.

Applies to

ASP.NET Core 9.0 and other versions
Product Versions
ASP.NET Core 5.0, 6.0, 7.0, 8.0, 9.0

WriteAsJsonAsync(HttpResponse, Object, Type, JsonSerializerContext, String, CancellationToken)

Source:
HttpResponseJsonExtensions.cs

Write the specified value as JSON to the response body. The response content-type will be set to the specified content-type.

C#
public static System.Threading.Tasks.Task WriteAsJsonAsync (this Microsoft.AspNetCore.Http.HttpResponse response, object? value, Type type, System.Text.Json.Serialization.JsonSerializerContext context, string? contentType = default, System.Threading.CancellationToken cancellationToken = default);

Parameters

response
HttpResponse

The response to write JSON to.

value
Object

The value to write as JSON.

type
Type

The type of object to write.

context
JsonSerializerContext

A metadata provider for serializable types.

contentType
String

The content-type to set on the response.

cancellationToken
CancellationToken

A CancellationToken used to cancel the operation.

Returns

The task object representing the asynchronous operation.

Applies to

ASP.NET Core 9.0 and other versions
Product Versions
ASP.NET Core 7.0, 8.0, 9.0

WriteAsJsonAsync<TValue>(HttpResponse, TValue, CancellationToken)

Source:
HttpResponseJsonExtensions.cs

Write the specified value as JSON to the response body. The response content-type will be set to application/json; charset=utf-8.

C#
public static System.Threading.Tasks.Task WriteAsJsonAsync<TValue> (this Microsoft.AspNetCore.Http.HttpResponse response, TValue value, System.Threading.CancellationToken cancellationToken = default);

Type Parameters

TValue

The type of object to write.

Parameters

response
HttpResponse

The response to write JSON to.

value
TValue

The value to write as JSON.

cancellationToken
CancellationToken

A CancellationToken used to cancel the operation.

Returns

The task object representing the asynchronous operation.

Applies to

ASP.NET Core 9.0 and other versions
Product Versions
ASP.NET Core 5.0, 6.0, 7.0, 8.0, 9.0

WriteAsJsonAsync<TValue>(HttpResponse, TValue, JsonSerializerOptions, CancellationToken)

Source:
HttpResponseJsonExtensions.cs

Write the specified value as JSON to the response body. The response content-type will be set to application/json; charset=utf-8.

C#
public static System.Threading.Tasks.Task WriteAsJsonAsync<TValue> (this Microsoft.AspNetCore.Http.HttpResponse response, TValue value, System.Text.Json.JsonSerializerOptions? options, System.Threading.CancellationToken cancellationToken = default);

Type Parameters

TValue

The type of object to write.

Parameters

response
HttpResponse

The response to write JSON to.

value
TValue

The value to write as JSON.

options
JsonSerializerOptions

The serializer options to use when serializing the value.

cancellationToken
CancellationToken

A CancellationToken used to cancel the operation.

Returns

The task object representing the asynchronous operation.

Applies to

ASP.NET Core 9.0 and other versions
Product Versions
ASP.NET Core 5.0, 6.0, 7.0, 8.0, 9.0

WriteAsJsonAsync<TValue>(HttpResponse, TValue, JsonSerializerOptions, String, CancellationToken)

Source:
HttpResponseJsonExtensions.cs

Write the specified value as JSON to the response body. The response content-type will be set to the specified content-type.

C#
public static System.Threading.Tasks.Task WriteAsJsonAsync<TValue> (this Microsoft.AspNetCore.Http.HttpResponse response, TValue value, System.Text.Json.JsonSerializerOptions? options, string? contentType, System.Threading.CancellationToken cancellationToken = default);

Type Parameters

TValue

The type of object to write.

Parameters

response
HttpResponse

The response to write JSON to.

value
TValue

The value to write as JSON.

options
JsonSerializerOptions

The serializer options to use when serializing the value.

contentType
String

The content-type to set on the response.

cancellationToken
CancellationToken

A CancellationToken used to cancel the operation.

Returns

The task object representing the asynchronous operation.

Applies to

ASP.NET Core 9.0 and other versions
Product Versions
ASP.NET Core 5.0, 6.0, 7.0, 8.0, 9.0

WriteAsJsonAsync<TValue>(HttpResponse, TValue, JsonTypeInfo<TValue>, String, CancellationToken)

Source:
HttpResponseJsonExtensions.cs

Write the specified value as JSON to the response body. The response content-type will be set to the specified content-type.

C#
public static System.Threading.Tasks.Task WriteAsJsonAsync<TValue> (this Microsoft.AspNetCore.Http.HttpResponse response, TValue value, System.Text.Json.Serialization.Metadata.JsonTypeInfo<TValue> jsonTypeInfo, string? contentType = default, System.Threading.CancellationToken cancellationToken = default);

Type Parameters

TValue

The type of object to write.

Parameters

response
HttpResponse

The response to write JSON to.

value
TValue

The value to write as JSON.

jsonTypeInfo
JsonTypeInfo<TValue>

Metadata about the type to convert.

contentType
String

The content-type to set on the response.

cancellationToken
CancellationToken

A CancellationToken used to cancel the operation.

Returns

The task object representing the asynchronous operation.

Applies to

ASP.NET Core 9.0 and other versions
Product Versions
ASP.NET Core 7.0, 8.0, 9.0