Dear all below is my code although I have 2Lakh rows coming but the json size becomes 48MB , check the below code and let me know as when I run this code the visual studio get hangs
public JsonResult GetEmployeesLocation(string Country)
LocationAddress loc=new LocationAddress();
try
{
using(DBENTITY db=new DBENTITY())
{
List MyLoc=(from m in db.locations where m.country=="USA"
select new LocationAddress
{
State=g.state,
City=g.city,
village=g.village,
state_ID=(int)g.SID,
City_ID=(int)C_ID,
Village_ID=(int)V_ID,
});
LocationAddress.location=MyLoc
return Json(LocationAddress,JsonRequestBehavior.AllowGet);
}
}
when I hit the api using postman it says "error during serliazitaion or deserialization using hte json javascriptseriealizer, the length of the string exceeds the value set on maxjsonlength.
I have increased the size it return the data but system hangs as it is 48MB of data
Rijwan AnsariPosted Sep 17, 2022, 6:07 AM
Check this
https://www.uptech.team/blog/filter-1gb-json-on-frontend-and-not-crash-browser
How To Filter 1GB JSON On The Frontend And Not Crash The Browser
Vishal JoshiPosted Sep 16, 2022, 11:26 AM
Hello Mark,
You can stringify JSON data to reduce size.
you can use library called Newtonsoft.Json. below is the common to install.
Install-Package Newtonsoft.Json -Version 13.0.1
Below is the sample code you can stringyfy JSON
It will convert data as below format
"[\r\n {\r\n \"Result\": null,\r\n \"Description\": null,\r\n \"Id\": 0,\r\n \"employee\": \"fata\",\r\n \"department\":
In Javascrip you can use JSON.Parse() to get back in the expected format.
Mark TaborPosted Sep 14, 2022, 5:28 AM
Jignesh Kumar dear I cannot do paging as It is not listing , The point is this is the manager login form when he login first time I want to get all location data from table having 200000 rows and save it in local storage , why the data is 60 MB , can we apply serialization or decerlizaation to reduce the size or my approach of api writing is wrong , I check your provided code as well but it still give lenth issue with return New JSON .
Jignesh KumarPosted Sep 14, 2022, 4:37 AM
Hi Mark,
If you have huge volume of data in respone then you can implement pagination and bring only require data to display.
https://www.c-sharpcorner.com/article/how-to-implement-paging-using-skip-and-take-operators-in-linq/
Anoop Kumar SharmaPosted Sep 14, 2022, 3:42 AM
Hi Mark,
You can use the paging concept with the Web API to send the data in chunks based upon the page and page size. I already worked with the such APIs which returns large dataset.
You can also refer to below link in case you want to see pagination implementtion in ASP.NET Web API.
https://code-maze.com/paging-aspnet-core-webapi/
I hope this will help you.
Mark TaborPosted Sep 13, 2022, 6:21 PM
"[\r\n {\r\n \"Result\": null,\r\n \"Description\": null,\r\n \"Id\": 0,\r\n \"employee\": \"fata\",\r\n \"department\":
getting this format how to format it
Mark TaborPosted Sep 13, 2022, 5:24 PM
Thanks Sachin Singhv & Jignesh Kumar for the response , I am getting data in visual studio even in postman i am getting data as i increased the maxjonlength to int.maxvalue, but the issue is it return 48 MB of data which hands my machine and everything , actuall the table has 300000 rows and 6 columns only with int and string so how it can make 48 MB
Sachin SinghPosted Sep 13, 2022, 2:46 PM
So, in VS you are getting data without any issue when you put debugger?
Mark TaborPosted Sep 13, 2022, 2:03 PM
Dear Sachin Singh its not related to vs i am checking using postman it is huge data even though if there are one million record it should not exceed 15-20 MB , the issue might be intentiating the new object everytime check the above code
Sachin SinghPosted Sep 13, 2022, 10:55 AM
Which VS version are you using, for VS 2019 and VS 2022, this issue is fixed.
Please use the latest VS. You can still work on old workloads (webform) with VS 2022
Mark TaborPosted Sep 13, 2022, 6:15 AM
The issue is larger size around 48 MB Jignesh Kumar
Jignesh KumarPosted Sep 13, 2022, 3:40 AM
Hi Mark,
Please use this to make it work,