title: Handling json pretty print param in ASP.NET Web API application in HttpConfiguration instance
body: <p>I need to add and handle optional "pretty" parameter in my ASP.NET Web API application.
  When user sends "pretty=true", the application response should look like a human-readable json with indentations.
  When user sends "pretty=false" or does not send this parameter at all, he must get json with no space symbols in response.</p>
  
  <p>Here's what I have:
  <strong>Global.asax.cs</strong></p>
  
  <pre><code>public class WebApiApplication
          : HttpApplication
      {
          protected void Application_Start()
          {
              AreaRegistration.RegisterAllAreas();
              GlobalConfiguration.Configure(WebApiConfig.Register);
              FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
          }
      }
  </code></pre>
  
  <p><strong>WebApiConfig.cs</strong></p>
  
  <pre><code>public static class WebApiConfig
      {
          public static void Register(HttpConfiguration config)
          {
              config.Filters.Add(new ValidateModelAttribute());
              config.Formatters.JsonFormatter.SerializerSettings = new JsonSerializerSettings
              {
                  NullValueHandling = NullValueHandling.Ignore,
                  Formatting = Newtonsoft.Json.Formatting.Indented
              };
              config.Formatters.JsonFormatter.SerializerSettings.Converters.Add(new Newtonsoft.Json.Converters.StringEnumConverter());
  ...
  </code></pre>
  
  <p>As you understand, I need the logic like this in <strong>Register</strong> method:</p>
  
  <pre><code>config.Formatters.JsonFormatter.SerializerSettings = new JsonSerializerSettings
              {
                  NullValueHandling = NullValueHandling.Ignore,
                  Formatting = Newtonsoft.Json.Formatting.Indented
              };
  if(prettyPrint) // must be extracted from request and passed here somehow
  {
     config.Formatters.JsonFormatter.SerializerSettings.Formatting = Newtonsoft.Json.Formatting.None;
  }
  </code></pre>
  
  <p>How it can be implemented? Maybe it should be handled some other way?</p>