How do I specify if I want JSON or XML in ASP.NET Web API?

It is defined by what the calling client (eg the browser or your .NET client) passes in the Accept header:

Accept: application/json, application/xml, text/json, text/xml

Will have a preference for JSON (if possible)

So your client that returns XML needs to set the Accept header to be the above or simply

Accept: application/json

should do the trick


To restrict output to only one formatter, try the instructions here:

http://www.asp.net/web-api/overview/formats-and-model-binding/json-and-xml-serialization#removing_the_json_or_xml_formatter

On a related note, the following link covers how ASP.NET Web API decides what output format to use depending on the HTTP request sent to it, i.e. how it chooses JSON over XML:

http://www.asp.net/web-api/overview/formats-and-model-binding/content-negotiation

It may be useful if you want to still support both formats, but need to ensure your own client code always receives JSON back.