Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting "The JSON request was too large to be deserialized"

You have to adjust the maxJsonLength property to a higher value in web.config to resolve the issue.

<system.web.extensions>
    <scripting>
        <webServices>
            <jsonSerialization maxJsonLength="2147483644"/>
        </webServices>
    </scripting>
</system.web.extensions>

Set a higher value for aspnet:MaxJsonDeserializerMembers in the appSettings:

<appSettings>
  <add key="aspnet:MaxJsonDeserializerMembers" value="150000" />
</appSettings>

If those options are not working you could try creating a custom json value provider factory using JSON.NET as specified in this thread.


If you don't want to change a global setting in the web config

Using a global setting will activate large json responses throughout your entire application which might open you up to a denial of service attack.

If a few choice locations are allowed this, you can very quickly use another json serialiser using the Content method like so:

using Newtonsoft.Json;

// ...

public ActionResult BigOldJsonResponse() 
{
    var response = ServiceWhichProducesLargeObject();
    return Content(JsonConvert.SerializeObject(response));
}
// ...