[ASP.Net] Configuring JSON Property Naming in ASP.NET Web API

발행일: Feb, 2025
조회수: 0
단어수: 84

Table of Contents

Default Behavior in ASP.NET

By default, when calling a Web API endpoint in ASP.NET, the JSON response properties are formatted in camel case. However, in C#, public class members are typically named using Pascal Case. If you want to keep Pascal Case in the JSON response, you can disable the default camel case transformation.

Disabling Camel Case Formatting

To disable camel case formatting in JSON responses, add the following code to the Program.cs file:

builder.Services
    .AddControllersWithViews()
    .AddJsonOptions(opt => opt.JsonSerializerOptions.PropertyNamingPolicy = null);

태그#ASP.NET#Web API#JSON#Pascal Case#Camel Case#C##.NET#JsonSerializerOptions#API Response Formatting

JUNA BLOG VISITORS

오늘0
Total0