TypedResults.Json Method

Definition

Overloads

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

Creates a JsonHttpResult<TValue> that serializes the specified data object to JSON.

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

Creates a JsonHttpResult<TValue> that serializes the specified data object to JSON.

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

Creates a JsonHttpResult<TValue> that serializes the specified data object to JSON.

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

Creates a JsonHttpResult<TValue> that serializes the specified data object to JSON.

public static Microsoft.AspNetCore.Http.HttpResults.JsonHttpResult<TValue> 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.HttpResults.JsonHttpResult<'Value>
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 JsonHttpResult(Of TValue)

Type Parameters

TValue

The type of object that will be JSON serialized to the response body.

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

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, JsonSerializerContext, String, Nullable<Int32>)

Creates a JsonHttpResult<TValue> that serializes the specified data object to JSON.

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

Type Parameters

TValue

The type of object that will be JSON serialized to the response body.

Parameters

data
TValue

The object to write as JSON.

context
JsonSerializerContext

A metadata provider for serializable types.

contentType
String

The content-type to set on the response.

statusCode
Nullable<Int32>

The status code to set on the response.

Returns

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

Applies to

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

Creates a JsonHttpResult<TValue> that serializes the specified data object to JSON.

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

Type Parameters

TValue

The type of object that will be JSON serialized to the response body.

Parameters

data
TValue

The object to write as JSON.

jsonTypeInfo
JsonTypeInfo<TValue>

Metadata about the type to convert.

contentType
String

The content-type to set on the response.

statusCode
Nullable<Int32>

The status code to set on the response.

Returns

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

Applies to