How do I get ASP.NET Web API to return JSON instead of XML using Chrome?

[Originally posted by]:

I just add the following in App_Start/WebApiConfig.cs class in my MVC Web API project.

config.Formatters.JsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/html") );

That makes sure you get json on most queries, but you can get xml when you send text/xml.

If you need to have the response Content-Type as application/json please check Todd’s answer below.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s