Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSON data size limit

In HighChart I needs to plot a series of data against x and y axis. HighChart expects the data to be in json format. ie, [ [ x, y],[x, y]……[x, y] ]. Where x and y are time ( 1392345000 – Unix epoch format ) and value ( 49.322 ). So I am making an ajax call to get the data and on success I render the json returned data in highchart. In most of the time ie, if the count of data( [x,y] ) is below 87500 rows than Json returns the data from controller to view. But when the data exceeds 87500 the ajax error is called with 404, not found error. Is there any size restriction for json returned data.

Section-1 – Controller Class

public JsonResult GetPlotData(Dictionary<string, List<ChartData>> dataPlot)
{

    // dataPlot = D00213 - [[13245678000,49.9],[13245345000,43.9]...[n,n]]
    // if dataPlot.Count < 87500 here throwing error and in ajax error 404 Not found
    return Json(dataPlot, JsonRequestBehavior.AllowGet);

}

Section-2 – Ajax

 $.ajax(
    {
          url: '../Report/GetPlotData',
          data: { "fromDate": fromDate, "toDate":toDate, "item": items[i].id }, 
          type: "POST",
          dataType: "json",
          cache: false,
          success: function(chartData) {
              alert(‘success’
          },
          error: function(xhr, ajaxOptions, thrownError) 
          {
                    debugger;
                    ShowDialogError(xhr, 'Site Status Report');
                  }
          });
like image 884
VVR147493 Avatar asked May 04 '14 00:05

VVR147493


People also ask

Is there a limit to string length in JSON?

The maximum length of JSON strings. The default is 2097152 characters, which is equivalent to 4 MB of Unicode string data.

What is JSON object size?

The size of a JSON array is the number of elements. As JSON arrays are zero terminated, the size of a JSON array is always the last index + 1.

What are the limitations and uses of JSON?

JSON isn't as robust a data structure as XML is.There is no ability to add comments or attribute tags to JSON, which limits your ability to annotate your data structures or add useful metadata. The lack of standardized schemas limits your ability to programmatically verify that your data is correct.


2 Answers

You webserver will limit the maximum response size limit. You should refer to documentation on your web server of choice to see how best to increase that limit beyond whatever it is set to today.

The JsonResult class does have a property (maxJsonLength) you may also try changing

var jsonResult = Json(dataPlot, JsonRequestBehavior.AllowGet);
jsonResult.MaxJsonLength = int.MaxValue;
return jsonResult;

Possible configuration change

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

Most importantly - you may want to reconsider your call to limit or somehow partition the responses into more manageable chunks as a default response limit is fairly large and can take a long time to return (network latency)

Generally speaking it's usually not a good idea to increase your response size limit. But that is probably the problem you are experiencing.

like image 81
Pepto Avatar answered Oct 02 '22 02:10

Pepto


var jsonResult = Json(dataPlot, JsonRequestBehavior.AllowGet);    
jsonResult.maxJsonLength = int.MaxValue;    
return jsonResult;

This is a best way to crease data limit in post.

like image 40
Jaimin Desai Avatar answered Oct 02 '22 03:10

Jaimin Desai