Compression works for XML but not JSON using IIS 7.5
<p>I'm trying to get my web service to send its JSON responses using gzip, but it never compresses the JSON response. But when I change the ContentType from application/json to text/plain, the gzip compression works.</p>

<pre><code>ContentType = "application/json" - Compression does not work
ContentType = "text/xml" - Compression works
ContentType = "text/plain" - Compression works
</code></pre>

<p>I'm using Fiddler to inspect HTTP requests and I can verify that I'm sending the requests with the Accept-Encoding: gzip, deflate header set. I've also tried with both Accept: <em>/</em> set to true.</p>

<p>HEADER REQUEST:</p>

<pre><code>*Proxy-Connection: keep-alive
Content-Length: 74
Cache-Control: max-age=0
Accept:     text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.103 Safari/537.36
Content-Type: application/x-www-form-urlencoded
Accept-Encoding: gzip, deflate
Accept-Language: en-GB,en-US;q=0.8,en;q=0.6*
</code></pre>

<p>SERVER RESPONSE:</p>

<pre><code>*HTTP/1.1 200 OK
Via: 1.1 EADIPROXY2
Connection: Keep-Alive
Proxy-Connection: Keep-Alive
Content-Length: 1424
Date: Tue, 23 Feb 2016 07:35:23 GMT
Content-Type: application/json
Server: Microsoft-IIS/7.5
Cache-Control: private, max-age=0
X-AspNet-Version: 2.0.50727
X-Powered-By: ASP.NET*
</code></pre>

<p>Adding or removing these lines in applicationHost.config seems to have no effect on the compression of XML and non-compression of JSON.</p>

<pre><code>&lt;staticTypes&gt;
            &lt;add mimeType="text/*" enabled="true" /&gt;
            &lt;add mimeType="message/*" enabled="true" /&gt;
            &lt;add mimeType="application/json" enabled="true" /&gt;
            &lt;add mimeType="application/json; charset=utf-8" enabled="true" /&gt;
        &lt;add mimeType="application/atom+xml" enabled="true" /&gt;
                &lt;add mimeType="application/atom+xml;charset=utf-8" enabled="true" /&gt;
                &lt;add mimeType="application/xaml+xml" enabled="true" /&gt;
            &lt;add mimeType="application/javascript" enabled="true" /&gt;
            &lt;add mimeType="application/x-javascript" enabled="true" /&gt;
            &lt;add mimeType="application/x-javascript; charset=utf-8" enabled="true" /&gt;
            &lt;add mimeType="*/*" enabled="false" /&gt;
            &lt;add mimeType="application/*" enabled="true" /&gt;
        &lt;/staticTypes&gt;
        &lt;dynamicTypes&gt;
            &lt;add mimeType="text/*" enabled="true" /&gt;
            &lt;add mimeType="message/*" enabled="true" /&gt;
            &lt;add mimeType="application/json" enabled="true" /&gt;
            &lt;add mimeType="application/json; charset=utf-8" enabled="true" /&gt;
            &lt;add mimeType="application/javascript" enabled="true" /&gt;
            &lt;add mimeType="application/x-javascript" enabled="true" /&gt;
            &lt;add mimeType="application/x-javascript; charset=utf-8" enabled="true" /&gt;
            &lt;add mimeType="*/*" enabled="false" /&gt;
            &lt;add mimeType="application/atom+xml" enabled="true" /&gt;
            &lt;add mimeType="application/atom+xml;charset=utf-8" enabled="true" /&gt;
        &lt;/dynamicTypes&gt;
    &lt;/httpCompression&gt;
</code></pre>

<p>I've disabled Dynamic Compression in IIS as it appended the {d:null} tag to the end of the JSON response and the compression doesn't work anyway.</p>