New! GraphQL.NET Cookbook by Senthil Kumar Balu

How to return JSON instead of XML in ASP.NET Web API when using Chrome ?

When using the ASP.NET Web API in Google Chrome , there are times when you see the XML output instead of JSON. You might want to request JSON data so that you can view it in the browser.

How to return JSON instead of XML in ASP.NET Web API when using Chrome ?

To get it to work , simply add the below code in the WebApiConfig.cs class in the App_Start folder of your ASP.NET WebAPI project.

 
config.Formatters.JsonFormatter.SupportedMediaTypes .
  Add(new MediaTypeHeaderValue("text/html") );
Senthil Kumar B
Senthil Kumar is a former Microsoft MVP (Most Valuable Professional). He is a Co-Author of the book "Windows 10 Development Recipes using JavaScript and CSS" for Apress Publication. He is a technical presenter, blogger, mentor and a Geek.  Senthil is a regular speaker is various local user groups. He has presented at conferences like Great Indian Developer Summit (GIDS) & Microsoft DevCamps. You can reach out to him via his Twitter handle @isenthil.