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

  • Home
  • SEARCH
  • 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 6546623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:43:49+00:00 2026-05-25T11:43:49+00:00

How does one return unescaped Json, using Json.Net in an MVC project? So far,

  • 0

How does one return unescaped Json, using Json.Net in an MVC project?

So far, I serialize a basic object, and get Json.Net to serialize it:

public JsonResult GetTimelineJson()
{
    var result = new MyGraph([some data...]);

    return Json(JsonConvert.SerializeObject(result), JsonRequestBehavior.AllowGet);
}

Result:

"{\r\n  \"id\": \"myGraph\",\r\n  \"title\": \"Graph title\",\r\n [...]

Any attempts to wrap it an an HtmlString, etc, result in an empty set being passed across the wire (though the debug point shows it correctly un-escaped). I’ve checked that the content-type is set correctly in the HTTP headers.

  • 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-05-25T11:43:50+00:00Added an answer on May 25, 2026 at 11:43 am

    The object is already serialized by Json.NET, and when you pass it to Json() it gets encoded twice. If you must use Json.NET instead of the built in encoder, then the ideal way to handle this would be to create a custom ActionResult accepts the object and calls Json.net internally to serialize the object and return it as an application/json result.

    EDIT

    This code is for the solution mentioned above. It’s untested, but should work.

    public class JsonDotNetResult : ActionResult
    {
        private object _obj { get; set; }
        public JsonDotNetResult(object obj)
        {
            _obj = obj;
        }
    
        public override void ExecuteResult(ControllerContext context)
        {
            context.HttpContext.Response.AddHeader("content-type", "application/json");
            context.HttpContext.Response.Write(JsonConvert.SerializeObject(_obj));
        }
    }
    

    and in your controller just do:

    return new JsonDotNetResult(result);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My question is when does any one need to return an object by reference?
How does one get a nested form id while using jquery? lets say the
If content is added to the DOM using, e.g., $(ul).append(<li>test</li>); how does one get
How does one consume web services that return JSON data in the response? I
inside of initWithConder self.superview will always return (null) for me. How does one get
dir(re.compile(pattern)) does not return pattern as one of the lists's elements. Namely it returns:
How does one go about programatically building a TemplateColumn object and adding it to
How does one return from a closure, without returning from the containing function? In
The thing is that it does return one row. Here's the thing. SELECT... FROM...
How does one deal with error return of a routine in C, when function

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.