Results.Json Method

Definition

Overloads

Json(Object, JsonSerializerOptions, String, Nullable<Int32>)

Creates a IResult that serializes the specified data object to JSON.

Json<TValue>(TValue, JsonSerializerOptions, String, Nullable<Int32>)

Creates a IResult that serializes the specified data object to JSON.

Json(Object, JsonSerializerOptions, String, Nullable<Int32>)

Creates a IResult that serializes the specified data object to JSON.

public static Microsoft.AspNetCore.Http.IResult Json (object? data, System.Text.Json.JsonSerializerOptions? options = default, string? contentType = default, int? statusCode = default);
static member Json : obj * System.Text.Json.JsonSerializerOptions * string * Nullable<int> -> Microsoft.AspNetCore.Http.IResult
Public Shared Function Json (data As Object, Optional options As JsonSerializerOptions = Nothing, Optional contentType As String = Nothing, Optional statusCode As Nullable(Of Integer) = Nothing) As IResult

Parameters

data
Object

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

statusCode
Nullable<Int32>

The status code to set on the response.

Returns

IResult

The created JsonHttpResult<TValue> that serializes the specified data as JSON format for the response.

Remarks

Callers should cache an instance of serializer settings to avoid recreating cached data with each call.

Applies to

Json<TValue>(TValue, JsonSerializerOptions, String, Nullable<Int32>)

Creates a IResult that serializes the specified data object to JSON.

public static Microsoft.AspNetCore.Http.IResult Json<TValue> (TValue? data, System.Text.Json.JsonSerializerOptions? options = default, string? contentType = default, int? statusCode = default);
static member Json : 'Value * System.Text.Json.JsonSerializerOptions * string * Nullable<int> -> Microsoft.AspNetCore.Http.IResult
Public Shared Function Json(Of TValue) (data As TValue, Optional options As JsonSerializerOptions = Nothing, Optional contentType As String = Nothing, Optional statusCode As Nullable(Of Integer) = Nothing) As IResult

Type Parameters

TValue

Parameters

data
TValue

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

statusCode
Nullable<Int32>

The status code to set on the response.

Returns

IResult

The created JsonHttpResult<TValue> that serializes the specified data as JSON format for the response.

Remarks

Callers should cache an instance of serializer settings to avoid recreating cached data with each call.

Applies to