Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

23
  • 120
    This is a surprisingly overlooked answer, and although the original question wasn't totally clear, this directly makes JSON the default response for a web browser (which sends Accept: text/html). Good job. Commented Jan 15, 2013 at 1:44
  • 17
    +1 Far and away the best answer. I imagine there are a ton of ppl who opt to completely remove XML just because they don't see JSON in the browser. Commented Nov 16, 2013 at 9:51
  • 4
    I found when I did this that data provided by a third party with HTML break tags in it ended up with carriage returns. The JSON was then invalid. Better to use the accepted answer if this affects you. Commented Mar 14, 2014 at 15:03
  • 25
    Note that the response's Content-Type header will still be text/html. Commented May 2, 2014 at 17:29
  • 86
    This is horrible. The response content type header should be application/json. This "solution" makes it text/html. Commented Jul 10, 2014 at 21:01