Skip to content

Respect JsonSerializerOptions casing for property names in validation errors #61764

Open

Description

@captainsafia

Background and Motivation

HttpValidationProblemDetails (returned by TypedResults.ValidationProblem, BadRequest(ModelState) and the automatic minimal-API parameter validation pipeline) currently reports member names exactly as they appear in CLR code (PascalCase). When an app opts into a different JSON naming policy—most commonly camelCase via

builder.Services.ConfigureHttpJsonOptions(o =>
    o.SerializerOptions.PropertyNamingPolicy = JsonNamingPolicy.CamelCase);

the payload that describes the validation failure no longer matches the property names clients actually send or expect to receive. This breaks tooling that relies on the error object for UI-binding or automatic form generation and is inconsistent with other framework-generated JSON (OpenAPI, regular serialization, etc.). 

The root cause is that the code paths in src/Http/Http.Abstractions/src/Validation choose ValidationResult.MemberName from reflection data (PropertyInfo.Name) without running it through the serializer’s PropertyNamingPolicy.

Reproduction

using System.ComponentModel.DataAnnotations;
using System.Text.Json;
var builder = WebApplication.CreateBuilder(args);

builder.Services.ConfigureHttpJsonOptions(o =>
    o.SerializerOptions.PropertyNamingPolicy = JsonNamingPolicy.CamelCase);

var app = builder.Build();

app.MapPost("/people", (Person p) => Results.Ok(p));

app.Run();

record Person([Required] string FirstName, [Required] string LastName);

Request

POST /people
Content-Type: application/json

{ "firstName": "Ada" }     //  lastName is missing

⸻

Current output

{
  "type": "https://tools.ietf.org/html/rfc9110#section-15.5.41",
  "title": "One or more validation errors occurred.",
  "status": 400,
  "errors": {
    "LastName": [
      "The LastName field is required."
    ]
  }
}

Notice the PascalCase LastName.

⸻

Expected output

{
  "type": "https://tools.ietf.org/html/rfc9110#section-15.5.41",
  "title": "One or more validation errors occurred.",
  "status": 400,
  "errors": {
    "lastName": [
      "The lastName field is required."
    ]
  }
}

The member name should respect the configured naming policy or any [JsonPropertyName] attribute.

The fix for this should include:

Because the validation helpers live entirely in Http.Abstractions, the change is self-contained and should not affect MVC's codepaths.

Activity

  1. ghost added
    area-blazor
    on May 1, 2025
  2. added
    feature-validation
    area-minimal
    and removed
    area-blazor
    on May 1, 2025
  3. added
    api-ready-for-review
    on Jun 9, 2025
  4. dotnet-policy-service commented on Jun 9, 2025

    @dotnet-policy-service
    Contributor

    Thank you for submitting this for API review. This will be reviewed by @dotnet/aspnet-api-review at the next meeting of the ASP.NET Core API Review group. Please ensure you take a look at the API review process documentation and ensure that:

    • The PR contains changes to the reference-assembly that describe the API change. Or, you have included a snippet of reference-assembly-style code that illustrates the API change.
    • The PR describes the impact to users, both positive (useful new APIs) and negative (breaking changes).
    • Someone is assigned to "champion" this change in the meeting, and they understand the impact and design of the change.
  5. added this to the Backlog milestone on Jul 23, 2025
  6. Youssef1313 commented on Jun 19, 2026

    @Youssef1313
    Member

    This seems similar to #63290 and probably both should be considered together.

  7. Youssef1313 commented on Jun 19, 2026

    @Youssef1313
    Member

    @oroztocil This is marked as api-ready-for-review but doesn't propose a public API. The linked closed PR introduces a public json options property on ValidateContext so I assume this was the public API Safia intended to propose?

  8. removed
    api-ready-for-review
    on Jun 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area-minimalfeature-validation

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions