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 7713979
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T02:00:31+00:00 2026-06-01T02:00:31+00:00

Context Language: C# Platform Version: Microsoft .Net Framework 4.0 Operating System: Windows 7 Professional

  • 0

Context
Language: C#
Platform Version: Microsoft .Net Framework 4.0
Operating System: Windows 7 Professional (64-bit)
Constraints: Microsoft MVC.Net 3.0

Problem
I find myself looking at JSON a lot in a browser these days, pointing a browser at one Controller Action or another on my local dev server and parsing JSON visually to make sure everything is being formatted the way we want. The JSON returned by the MVC 3 serializer (or the JSON.Net serializer) always return a minified string, so I wind up with something like this:

{"Bars":[{"Name":"Ghost Bar","Address":"2440 Victory Park Lane, 33rd Floor, Dallas, TX 75219","OpenDate":"\/Date(1208062800000)\/","Status":"Open"},{"Name":"M-Street Bar","Address":"5628 Sears Street, Dallas, TX 75206","OpenDate":"\/Date(1064811600000)\/","Status":"Closed"},{"Name":"Zephyr\u0027s Lounge","Address":"3520 Greenville Avenue, Dallas, TX 75206","OpenDate":"\/Date(981007200000)\/","Status":"Open"}]}

Question
I’d really like to find a way, at least during debugging, to get the JsonResult to be “prettified” so that it looks more like this:

{
  "Bars": [
    {
      "Name": "Ghost Bar",
      "Address": "2440 Victory Park Lane, 33rd Floor, Dallas, TX 75219",
      "OpenDate": "\/Date(1208062800000)\/",
      "Status": "Open"
    },
    {
      "Name": "M-Street Bar",
      "Address": "5628 Sears Street, Dallas, TX 75206",
      "OpenDate": "\/Date(1064811600000)\/",
      "Status": "Closed"
    },
    {
      "Name": "Zephyr\u0027s Lounge",
      "Address": "3520 Greenville Avenue, Dallas, TX 75206",
      "OpenDate": "\/Date(981007200000)\/",
      "Status": "Open"
    }
  ]
}

I am aware of several online tools that will let you paste and format JSON. The is an extra step, and is costing me a lot of time. I’d prefer a programmatic solution. I’d also like to be able to turn it on/off via configuration or an #if compiler directive.

I have already done a cursory search regarding this and come across this post on Stack Overflow. However, the code example given is quite incomplete. There are also a couple of links provided but they appear to be dead.

In any case, I’d like to find a way to get “prettified” JSON out of an ActionResult. Any help appredciated.

The following source code will reproduce the initial un-prettified JSON string I gave as an example. Feel free to copy/pasted/edit.

using System.Collections.Generic;
using System.Text;
using System.Web.Mvc;

namespace PrettyJsonResult.Controllers
{
    public class DefaultController : Controller
    {
        public JsonResult Index()
        {
            var foo = new Foo();
            foo.Bars.Add(new Bar { Address = "2440 Victory Park Lane, 33rd Floor, Dallas, TX 75219", Name = "Ghost Bar", Status = "Open" });
            foo.Bars.Add(new Bar { Address = "5628 Sears Street, Dallas, TX 75206", Name = "M-Street Bar", Status = "Closed" });
            foo.Bars.Add(new Bar { Address = "3520 Greenville Avenue, Dallas, TX 75206", Name = "Zephyr's Lounge", Status = "Open" });

            return Json(foo, "application/json", Encoding.UTF8, JsonRequestBehavior.AllowGet);
        }

    }

    public class Foo
    {
        public Foo()
        {
            Bars = new List<Bar>();
        }

        public List<Bar> Bars { get; set; }
    }

    public class Bar
    {
        public string Name { get; set; }
        public string Address { get; set; }
        public string Status { get; set; }
    }
}
  • 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-01T02:00:33+00:00Added an answer on June 1, 2026 at 2:00 am

    Not much of an answer, but if you switch your Json serializer from the built in one (JavaScriptSerializer) to Json.NET (which has a bunch of advantages beyond this issue), you can do something like this :

    JsonConvert.SerializeObject( myObjectDestinedForJSON, Formatting.Indented);
    

    Docs on the settings here : http://james.newtonking.com/projects/json/help/

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

Sidebar

Related Questions

Here's the scenario: Platform: Windows IDE: Microsoft Visual Studio 2008 Language: C# .NET framework:
Problem Language: C# 2.0 or later I would like to register context handlers to
Whenever I learn a new language/framework, I always make a content management system... I'm
I have a problem with the following language: I must write a context-free grammar:
Possible Duplicate: Using D programming language in a .NET context Just curious, is it
Note: Although my particular context is Objective-C, my question actually transcends programming language choice.
Context: I'm in charge of running a service written in .NET. Proprietary application. It
In the context of programming language discussion/comparison, what does the term power mean? Does
We are using NetBeans Platform 7.0.1, and have implemented support for a new language
I'm designing a context-free grammar to generate this language: { w in {a,b}* |

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.