ASP.NET MVC5: Configure JSON Format with Camel-Case Notation
Today, I shall be demonstrating configuration of JSON format with camel case notation and removing extra slashes using ASP.NET REST Web API platform.
Prerequisites:Following are some prerequisites before you proceed any further in this tutorial.
- Knowledge of Camel Case Notation.
- Knowledge of Pascal Case Notation.
- Knowledge of REST Web API.
- Knowledge of ASP.NET MVC5.
- Knowledge of C# Programming.
1) Create a new Web API project and name it "WebApiJsonFormat".
2) Install Json.NET - Newtonsoft via Nuget Package Manager.
3) Now, create your .NET JSON object mappers based on your JSON data either manually or via Json2Csharp online tool. I am using following JSON sample with .NET object mapper i.e.
Sample JSON Data
C#.NET Json Object Mapper
Notice in the above sample JSON that property/key names do not have proper naming convention i.e. either camel case or pascal case notation. On the other hand the C#.NET object mapper class, the properties are in pascal notation i.e. first letter is capital, but, as we create our JSON response our requirements needed responding JSON in Camel case notation.
4) In next step create your web API method either POST or GET, I am making a simple HTTP POST method which after de-serializing the input JSON, serializes it back and send response.
8) To fix camel case notation issue in my response JSON data, add following lines of code at the end of "Register(...)" method in "App_Start ->WebApiConfig.cs" file i.e.
The above lines of code will be effective only whenever I use JsonConvert to serialize my JSON data object.
9) Now, upon executing the project, you can see that now my response JSON object in standard format with camel case notation according my business requirements i.e.