๐Ÿ˜œ

์ญˆ๋‚˜์•„๋น  ๋ธ”๋กœ๊ทธ

JUNA
STUDIO

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

๋ฐœํ–‰์ผ: Feb, 2025
์กฐํšŒ์ˆ˜: 2
๋‹จ์–ด์ˆ˜: 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);

Tags: #ASP.NET#Web API#JSON#Pascal Case#Camel Case#C##.NET#JsonSerializerOptions#API Response Formatting
JUNA BLOG VISITORS
Today
7
 (
updown
-7
)
Total
657
 (
updown
+7
)

ยฉ 2025 juniyunapapa@gmail.com.