System.Text.Json is the .NET library for reading and writing JSON. ASP.NET Core uses it by default because it provides high-performance, low-allocation serialization and deserialization, while offering less flexibility than Newtonsoft.Json. section 7.3 section 20.7
In minimal APIs, System.Text.Json handles JSON request bodies and responses automatically:
- Deserialize one JSON request body into a single complex handler parameter. section 5.2.3 section 7.3
- Serialize endpoint results as JSON when returning API responses. section 7.3
- Customize options such as trailing commas, camelCase property names, and case-insensitive property matching. section 7.3
Binding a JSON request
A minimal API can accept a Product parameter directly. ASP.NET Core deserializes the JSON request body into a Product instance before invoking the handler. The request must contain valid JSON, and only one handler parameter can bind this way. section 7.3
WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
builder.Services.ConfigureRouteHandlerJsonOptions(o => {
o.SerializerOptions.AllowTrailingCommas = true;
o.SerializerOptions.PropertyNamingPolicy = JsonNamingPolicy.CamelCase;
o.SerializerOptions.PropertyNameCaseInsensitive = true;
});
Use route-handler JSON options to permit trailing commas, apply camelCase naming, and accept property names without matching case. section 7.3


