Skip to main content
15 events
when toggle format what by license comment
May 23, 2017 at 12:10 history edited URL Rewriter Bot
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Mar 7, 2017 at 12:34 review Suggested edits
Mar 7, 2017 at 13:32
Nov 24, 2016 at 6:09 comment added DonDon The solution doesn't work with IE (e.g. still asking to download json file). Any fix for this ?
Jan 26, 2016 at 19:49 comment added wize To make sure international characters are returned correcty, set the correct charset by adding the line headers.ContentType.CharSet = "utf-8"; to the bottom of SetDefaultContentHeaders() function.
Sep 16, 2015 at 1:46 comment added Berriel For the googlers who are looking for: don't forget to add using System.Net.Http.Formatting and using Newtonsoft.Json
Sep 3, 2015 at 20:10 comment added Jester Thanks Todd, best answer: 1) Correct return type, 2) keeps pretty formatting ONLY from a browser AND 3) I don't have to add a new accept type to Firefox and Chrome works also! Sweetness.
Feb 12, 2015 at 20:53 comment added Northstrider @eddiegroves you dont want pretty-print over the wire. You want the server to send the least amount of bits over the wire (ie: no spaces). Then you want the browser to format it nicely, with addons and such. Javascript needs to parse the JSON usually, why make it slower by introducing unnecessary formatting
Dec 15, 2014 at 18:31 comment added Todd Menier @AlastairMaw good idea, added your suggestion so pretty-printing works without the browser extension.
Dec 15, 2014 at 18:30 history edited Todd Menier CC BY-SA 3.0
added suggestion from comments
Dec 1, 2014 at 12:00 comment added H.Wolper Isn't @dmit77 's Answer better (more concise) than this one?
Jul 21, 2014 at 6:20 comment added Eddie Groves @meffect pretty-printing is preferred when viewing in a browser. Clients requesting json via application/json would still have non indented json returned.
Jul 10, 2014 at 21:04 comment added Northstrider why would you want it to pretty print over the wire?
Jul 1, 2014 at 17:49 comment added Nick Perfect. I was having issues with Felipe's solution returning a Content-Type of text/html and this fixed it (and made the response correct!) I combined your answer with suhair's answer so that I get JSON sent to the browser by default but have the option of adding "format=xml" or "format=json" to the querystring to select a specific formatter. Thanks!
May 15, 2014 at 14:48 comment added Alastair Maw In the constructor add this.SerializerSettings.Formatting = Formatting.Indented; if you want it pretty-printed without a browser extension.
Dec 12, 2013 at 23:52 history answered Todd Menier CC BY-SA 3.0