Results.Json Method

Definition

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