Answers.Body: <p>It appears whitespace was the cause here, just running a quick whitespace filer on the return value resolved the issue:</p>
  
  <pre><code>$userHtml = craft()-&gt;logic-&gt;renderSiteMacro('_macros/elements', 'listing', $args);
  
  $userHtml = preg_replace('~&gt;\\s+&lt;~m', '&gt;&lt;', $userHtml);
  
  $this-&gt;returnJson(array(
      'success' =&gt; true,
      'existing' =&gt; $userHtml
  ));
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-24T10:21:50.890Z
Answers.LastActivityDate: 2015-04-24T10:36:03.357Z
Answers.LastEditDate: 2015-04-24T10:36:03.357Z
Answers.UserDisplayName: Sam Hibberd
Body: <p>Im running in to issues with returnJson not returning html or just returning and empty object:</p>
  
  <pre><code>$userHtml = craft()-&gt;logic-&gt;renderSiteMacro('_macros/elements', 'listing', $args);
  
  $this-&gt;returnJson(array(
       'success' =&gt; true,
       'existing' =&gt; $userHtml
  ));
  </code></pre>
  
  <p>The return JSON is always:</p>
  
  <pre><code>{"success":true,"existing":{}}
  </code></pre>
  
  <p>I have double checked the html output exists and the issue persists: </p>
  
  <ul>
  <li>Whether returning a simple string or large chunk of html</li>
  <li>And with and without single quotes</li>
  <li>When renderSiteMacro functions runs the code through the raw filter and not</li>
  </ul>
  
Tags: <plugin-development><controller>
Title: Issues with returnJson not returning html?
ThreadText: # Issues with returnJson not returning html?
  
  (Asked by: username_0 on 2015-04-24)
  
  Im running in to issues with returnJson not returning html or just returning and empty object:
  
  ```
  $userHtml = craft()->logic->renderSiteMacro('_macros/elements', 'listing', $args);
  
  $this->returnJson(array(
       'success' => true,
       'existing' => $userHtml
  ));
  
  ```
  
  The return JSON is always:
  
  ```
  {"success":true,"existing":{}}
  
  ```
  
  I have double checked the html output exists and the issue persists:
  
  * Whether returning a simple string or large chunk of html
  * And with and without single quotes
  * When renderSiteMacro functions runs the code through the raw filter and not
  
  **Tags:** plugin-development, controller
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2015-04-24. Score: 4
  
  It appears whitespace was the cause here, just running a quick whitespace filer on the return value resolved the issue:
  
  ```
  $userHtml = craft()->logic->renderSiteMacro('_macros/elements', 'listing', $args);
  
  $userHtml = preg_replace('~>\\s+<~m', '><', $userHtml);
  
  $this->returnJson(array(
      'success' => true,
      'existing' => $userHtml
  ));
  
  ```
  
  
  ---
  
  