Answers.Body: <p>I had the same problem. See Brad's response here to so this without messing with devMode: <a href="https://craftcms.stackexchange.com/questions/488/console-script-tags-garbling-up-non-html-output-e-g-json-when-in-devmode">Console script tags garbling up non-html output (e.g. json) when in devMode</a></p>
  
  <p>It would be nice if this happened automatically when specifically outputting non-html, though.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-11T03:32:09.110Z
Answers.LastActivityDate: 2014-07-11T03:32:09.110Z
Answers.LastEditDate: 2017-04-13T12:51:00.253Z
Answers.UserDisplayName: Tim Kelty
Answers.Body: <p>As of <a href="http://buildwithcraft.com/updates#build2579" rel="nofollow">Craft 2.2</a>, Craft will now only add the logs to the response if the Content-Type header is going to be "text/html" or "application/xhtml+xml". Should solve this for you.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-09-02T19:43:09.187Z
Answers.LastActivityDate: 2014-09-02T19:43:09.187Z
Answers.UserDisplayName: Brandon Kelly
Answers.Body: <p>You can turn off dev mode for just this page/call if you'd like, using the <a href="http://buildwithcraft.com/docs/apis/configservice#set" rel="nofollow"><code>config-&gt;set</code> API method</a>.</p>
  
  <pre><code>craft()-&gt;config-&gt;set('devMode', false);
  </code></pre>
  
  <p>Don't forget to turn it back on after your function runs (if it still matters at that point).</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-11T02:34:54.900Z
Answers.Text: Thank you! I'm setting devMode=false right before calling the BaseController::returnJson method. This is okay because the returnJson method spins down craft with craft->end() after echo'ing the json encoded data.
Answers.UserDisplayName: Tyler Willingham
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-11T02:17:07.813Z
Answers.LastActivityDate: 2014-07-11T02:17:07.813Z
Answers.UserDisplayName: Lindsey D
Body: <p>While developing an API for a client site I recognized that there was a  tag being returned after our JSON response (generated using BaseController's returnJson method).</p>
  
  <p>I copy &amp; pasted some of the output into The Google and found a reference to the <em>YII_DEBUG</em> constant. I checked the value (true) and assumed it was related to devMode. I turned off devMode for this environment and the extra code went away (and YII_DEBUG===false).</p>
  
  <p>I don't suspect that this extra output is expected while using the returnJson() method but I need to get around this. Can I turn off devMode outside of the config file? I really only want to make an exception when calling this method.</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-07-11T02:35:44.260Z
Comments.Text: The question has been answered but I'd love to hear from P&T on whether or not this may change in a future release
Comments.UserDisplayName: Tyler Willingham
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-07-11T03:07:36.603Z
Comments.Text: What exactly is the extra output? Is it a bunch of `console.log()` calls (the profiler info)?
Comments.UserDisplayName: Brandon Kelly
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-07-11T09:17:50.267Z
Comments.Text: Yup, that's correct. There are a bunch of console.log calls
Comments.UserDisplayName: Tyler Willingham
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-07-11T16:17:58.330Z
Comments.Text: Got it. Right now Craft will only hide those if it’s an Ajax request. Would make sense that it’s based on the MIME type instead, though.
Comments.UserDisplayName: Brandon Kelly
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-07-11T16:38:19.297Z
Comments.Text: I agree. I can't think of a situation where I would actually want that output in my JSON file :)
Comments.UserDisplayName: Tyler Willingham
Tags: <plugin-development><json>
Title: BaseController::returnJson & devMode interference
ThreadText: # BaseController::returnJson & devMode interference
  
  (Asked by: username_0 on 2014-07-11)
  
  While developing an API for a client site I recognized that there was a tag being returned after our JSON response (generated using BaseController's returnJson method).
  
  I copy & pasted some of the output into The Google and found a reference to the *YII\_DEBUG* constant. I checked the value (true) and assumed it was related to devMode. I turned off devMode for this environment and the extra code went away (and YII\_DEBUG===false).
  
  I don't suspect that this extra output is expected while using the returnJson() method but I need to get around this. Can I turn off devMode outside of the config file? I really only want to make an exception when calling this method.
  
  **Tags:** plugin-development, json
  
  > **Comments:**
  > **username_0**: The question has been answered but I'd love to hear from P&T on whether or not this may change in a future release  
  > **username_1**: What exactly is the extra output? Is it a bunch of `console.log()` calls (the profiler info)?  
  > **username_0**: Yup, that's correct. There are a bunch of console.log calls  
  > **username_1**: Got it. Right now Craft will only hide those if it’s an Ajax request. Would make sense that it’s based on the MIME type instead, though.  
  > **username_0**: I agree. I can't think of a situation where I would actually want that output in my JSON file :)  
  
  ---
  
  ## 3 answers
  
  ### Answer by username_2 on 2014-07-11. Score: 4 | Accepted answer
  
  I had the same problem. See Brad's response here to so this without messing with devMode: [Console script tags garbling up non-html output (e.g. json) when in devMode](https://craftcms.stackexchange.com/questions/488/console-script-tags-garbling-up-non-html-output-e-g-json-when-in-devmode)
  
  It would be nice if this happened automatically when specifically outputting non-html, though.
  
  
  ---
  
  ### Answer by username_1 on 2014-09-02. Score: 3
  
  As of [Craft 2.2](http://buildwithcraft.com/updates#build2579), Craft will now only add the logs to the response if the Content-Type header is going to be "text/html" or "application/xhtml+xml". Should solve this for you.
  
  
  ---
  
  ### Answer by username_3 on 2014-07-11. Score: 1
  
  You can turn off dev mode for just this page/call if you'd like, using the [`config->set` API method](http://buildwithcraft.com/docs/apis/configservice#set).
  
  ```
  craft()->config->set('devMode', false);
  
  ```
  
  Don't forget to turn it back on after your function runs (if it still matters at that point).
  
  > **Comments:**
  > **username_0**: Thank you! I'm setting devMode=false right before calling the BaseController::returnJson method. This is okay because the returnJson method spins down craft with craft->end() after echo'ing the json encoded data.  
  
  ---
  
  