Full Stack Developer — I want to return JSON just like all the cool kids...

1.5M ratings
277k ratings

See, that’s what the app is perfect for.

Sounds perfect Wahhhh, I don’t wanna

I want to return JSON just like all the cool kids with WebApi 2.0

I added BrowserJsonFormatter:

public class BrowserJsonFormatter : JsonMediaTypeFormatter{
    public BrowserJsonFormatter()
    {
        this.SupportedMediaTypes.Add(new         MediaTypeHeaderValue("text/html"));
    this.SerializerSettings.Formatting = Formatting.Indented;
}     public override void SetDefaultContentHeaders(Type type,    HttpContentHeaders headers, MediaTypeHeaderValue mediaType)
    {
    base.SetDefaultContentHeaders(type, headers, mediaType);
    headers.ContentType = new    MediaTypeHeaderValue("application/json");
    } }

To the application and then registered it in App_Start/WebApiConfig.cs:

public static class WebApiConfig{

       public static void Register(HttpConfiguration config){
               // Web API configuration and services        // Web API routes
      config.MapHttpAttributeRoutes();       config.Routes.MapHttpRoute(
      name: "DefaultApi",
      routeTemplate: "api/{controller}/{id}",
      defaults: new { id = RouteParameter.Optional }
);

     config.Formatters.Add(new BrowserJsonFormatter());
    }
}

Now I feel like a hipster. ;-)