<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>

CC BY-SA 3.0
2014-07-11T03:32:09.110Z
2014-07-11T03:32:09.110Z
2017-04-13T12:51:00.253Z
Tim Kelty
<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>

CC BY-SA 3.0
2014-09-02T19:43:09.187Z
2014-09-02T19:43:09.187Z
Brandon Kelly
<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>

CC BY-SA 3.0
2014-07-11T02:34:54.900Z
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.
Tyler Willingham
CC BY-SA 3.0
2014-07-11T02:17:07.813Z
2014-07-11T02:17:07.813Z
Lindsey D
<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>

CC BY-SA 3.0
2014-07-11T02:35:44.260Z
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
Tyler Willingham
CC BY-SA 3.0
2014-07-11T03:07:36.603Z
What exactly is the extra output? Is it a bunch of `console.log()` calls (the profiler info)?
Brandon Kelly
CC BY-SA 3.0
2014-07-11T09:17:50.267Z
Yup, that's correct. There are a bunch of console.log calls
Tyler Willingham
CC BY-SA 3.0
2014-07-11T16:17:58.330Z
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.
Brandon Kelly
CC BY-SA 3.0
2014-07-11T16:38:19.297Z
I agree. I can't think of a situation where I would actually want that output in my JSON file :)
Tyler Willingham
<plugin-development><json>
BaseController::returnJson & devMode interference
# 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.
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.  

---

