Jonathan S. Jonathan S. - 11 months ago 69
JSON Question

Confusion over maxJsonLength default value

I'm hoping to get some clarification on the maxJsonLength property. Here is some background information.

I was having an issue with an AJAX response not being returned in a .NET web application using jQuery. When the user changed a drop down list, I manually built and displayed some HTML. The issue was that one specific selection returned a string that was about 140kB but it would not display in the browser. I narrowed the problem down to the length of the string being too long. In searching SO and elsewhere, I found that the issue could be resolved by manually setting the value of maxJsonLength in my web.config.

My confusion is about the default value of th maxJsonLength property. Some answers say it's 2097152 characters and reference this MSDN link. But others have said the default length is 102400 and reference this other MSDN link. In my testing, I've come to the conclusion that the default is 102400 bytes but I'm not sure of the reason for the other default value.

Answer Source

Creating a page on a website with the following in the code behind:

JavaScriptSerializer serializer = new JavaScriptSerializer();

Response.Write("Max Length: " + serializer.MaxJsonLength);

Led to an output of:

Max Length: 2097152

So I would go with the value defined in the docs rather than the How to.

Note however that this is Characters, and not bytes explicitly:

The default is 2097152 characters, which is equivalent to 4 MB of Unicode string data