Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8980887
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:11:52+00:00 2026-06-15T20:11:52+00:00

I’m returning a JSON structure from an MVC action that looks something like this:

  • 0

I’m returning a JSON structure from an MVC action that looks something like this:

[HttpPost]
public ActionResult GetStudents(string name) 
{   
    //
    // Filter list of students...
    //

    return Json(new {
        aaData = students.ToList().Select(s => new [] {
            String.Format(@"<span style='display:none;'>{0}</span>{1}", s.Id, s.StudentNumber),
            String.Format(@"<a href='../../Student/Details/{0}'>{1}</a>", s.Id, s.FullName),
            String.Format(@"<a href='../../Student/Edit/{0}'>Edit</a>", s.Id)
        })
    }, JsonRequestBehavior.DenyGet);
}

The resulting JSON is coming out looking like this:

{"aaData":
    [
        ["\u003cspan style=\u0027display:none;\u0027\u003e3\u003c/span\u003e009165",
         "\u003ca href=\u0027../../Student/Details/3\u0027\u003eJohn Smith\u003c/a\u003e",
         "\u003ca href=\u0027../../Student/Edit/3\u0027\u003eEdit\u003c/a\u003e"],

        ... Lots more ...
    ]
}

Which works fine. But the full JSON comes out to be around 1.7 MB. I think that this could be trimmed down significantly if the HTML tags within the JSON weren’t all unicode encoded. According to the JSON spec, it doesn’t look like these would need to be encoded:

any-Unicode-character-
except-“-or-\-or-
control-character

Is there any way keep .NET from writing out the JSON this way, or is there any other way to trim down the amount of data that I need to transmit?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T20:11:53+00:00Added an answer on June 15, 2026 at 8:11 pm

    The first thing to do is replace the JSON serializer, by creating your own result class and controller extension methods for producing it.

    Something along the lines of:

    public class FastJsonResult : ActionResult // or maybe derive from JsonResult
    {
        private object model;
    
        public FastJsonResult(object model) 
        {
            this.model = model;
        }
    
        public override void ExecuteResult(ControllerContext context)
        {
            // code to set content type and write serialized response
        }
    }
    

    And the controller extension method:

    public static class JsonControllerExtensions
    {
         public static ActionResult FastJson(this Controller controller, object model)
         {
             return new FastJsonResult(model);
         }
    }
    

    Allowing you to use your own serialization code like so:

    // at the end of your controller method:
    return new FastJson(model);
    

    You’ll need to plug in a serializer that formats your JSON response appropriately. I can strongly recommend using ServiceStack.Text for this (on NuGet), as it is extremely fast, easy to get up and running and supports most common scenarios. Another popular alternative to Microsoft’s built-in offering is NewtonSoft’s JsonSerializer (also on NuGet).

    The benefit of this approach is that you get better control over how your result is rendered. If you have large amounts of data to send, having a fast serializer can make quite a difference.

    That said, you really ought to only use JSON for sending data across the wire (as opposed to markup). Frameworks such as knockout make it very easy to do client-side rendering of JSON data retrieved from a server. Going in this direction should be your long term goal, but using a custom serializer will be a benefit to either solution.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I would like to run a str_replace or preg_replace which looks for certain words
I know there's a lot of other questions out there that deal with this
Does anyone know how can I replace this 2 symbol below from the string
I am using jsonparser to parse data and images obtained from json response. When
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.