Answers.Body: <p>Not a direct answer, but following on from the comments here are some more things you can try.</p>
  
  <ol>
  <li><p>If you haven't already, check the civicrm log. Maybe there is something helpful there. For example maybe there is a recoverable error happening but it dumps some output to stdout instead of the log, which during a REST call will be part of the response output.</p></li>
  <li><p>It's possible you have some code or an extension that implements the civicrm_caseChange hook and then does some debug output. When looking or grepping be sure to look in any custom php and extension folders defined at admin -> system settings -> directories.</p></li>
  <li><p>Use <code>diff -r</code> or <code>kdiff</code> or something to compare your civicrm tree to a fresh unzipped 5.12 download to see if there's any differences.</p></li>
  <li><p>It's definitely print_r output, but it might be coming indirectly from something that calls 'CRM_Core_Error::debug(' or 'CRM_Core_Error::debug_var(', so can try grepping for that. Note I've included the opening bracket in the search string since I'm thinking that will give the least false matches.</p></li>
  <li><p>Try disabling some extensions one by one.</p></li>
  <li><p>Run a <a href="https://xdebug.org/docs/remote" rel="nofollow noreferrer">php step-debugger</a> to see exactly what step it gets output and where it's coming from. This will be time consuming, but you will almost certainly find it. If you can reproduce the problem on a local development copy of the site it will be slightly easier to set this up using that copy.</p></li>
  </ol>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-04-13T17:14:22.160Z
Answers.Text: Genius, thank you. The problem was caused by an extension which included a function implementing the caseChange hook (the function is very short, and just sends an email whenever a case is changed). I've pasted it here: https://pastebin.com/qH94m7EX. I'm not sure why it's outputting the contents of $analyzer, or how this gets into the response of the api create function. Anyway, we don't need it, so I have just commented it out, and the api response is now just the expected json. Thanks very much for your help.
Answers.UserDisplayName: Jern
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-04-13T17:59:55.217Z
Answers.Text: Great. By the way in that function if you just change `print_r($analyzer);` to `print_r($analyzer, true);` it will work as it seems like it was intended. Without the "true" it sends the output to stdout instead of returning a string, which is why you see it in the REST output.
Answers.UserDisplayName: Demerit
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-04-13T18:31:08.643Z
Answers.Text: Another casualty of when debugging actually *causes* bugs.
Answers.UserDisplayName: Coleman
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-04-13T11:24:00.163Z
Answers.LastActivityDate: 2019-04-13T11:24:00.163Z
Answers.UserDisplayName: Demerit
Body: <p>I had a working script set up to create cases in CiviCRM using REST.<br/><a href="https://domain.com/administrator/components/com_civicrm/civicrm/extern/rest.php?entity=Case&amp;action=create&amp;json=1&amp;version=3&amp;key=xxxxxxxx&amp;api_key=yyyyyyy" rel="nofollow noreferrer">https://domain.com/administrator/components/com_civicrm/civicrm/extern/rest.php?entity=Case&amp;action=create&amp;json=1&amp;version=3&amp;key=xxxxxxxx&amp;api_key=yyyyyyy</a><br/>(obviously with the correct payload etc). This worked fine. It returned the specified return:id etc in a nice small JSON. Now, the same script is failing because it can't parse the returned JSON. It seems that the API is now returning a Civi\CCase\Analyzer Object which contains the full case data as XML and as JSON. Is this change intentional? Is it documented anywhere? I'm wondering how to extract the JSON from the returned Analyzer object. Thanks.</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-04-12T17:36:26.657Z
Comments.Text: I'm not seeing any xml when I run it (on a drupal site). Is there something interesting about the way you run it? I tested with: curl -X POST '`http://site/civicrm/extern/rest.php?json=1`' -H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' --data 'entity=Case&action=create&api_key=12345&key=12345&contact_id=user_contact_id&case_type_id=1&subject=fromExternRest'
Comments.UserDisplayName: Demerit
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-04-12T19:32:21.787Z
Comments.Text: Thanks. I tried the same thing as you, using curl, but the response I'm getting is a full dump of the newly-created Case in XML, including all associated activities and relationships, and then the JSON at the end of the output. I'm using Joomla, but I can't imagine that would make a difference? The script has been working fine for months, and I haven't done anything to it.
Comments.UserDisplayName: Jern
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-04-12T19:36:54.193Z
Comments.Text: The output starts like this, and goes on for a couple of thousand lines:
  Civi\CCase\Analyzer Object
  (
      [caseId:Civi\CCase\Analyzer:private] => 775
      [case:Civi\CCase\Analyzer:private] => Array
          (
              [id] => 775
              [case_type_id] => 9
              [subject] => fromExternRest
              [start_date] => 2019-04-12
              [status_id] => 1
              [is_deleted] => 0
              [created_date] => 2019-04-12 21:16:32
              [modified_date] => 2019-04-12 21:16:32
              [contact_id] => Array
                  (
                      [1] => 66
Comments.UserDisplayName: Jern
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-04-12T19:47:33.030Z
Comments.Text: Can you do a grep for var_dump or print_r? I'm thinking some debugging code was added in and is producing that output.
Comments.UserDisplayName: Demerit
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-04-12T23:19:43.887Z
Comments.Text: OK, I couldn't see anything which looks suspect. But maybe you can spot something. The grep output is here - https://pastebin.com/nRCKcCky and here:
  https://pastebin.com/Hu82Atgi
Comments.UserDisplayName: Jern
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-04-12T23:29:55.187Z
Comments.Text: Hmm. Is debugging is turned on in the admin screen? Maybe it's causing some extra output?
Comments.UserDisplayName: Demerit
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-04-13T01:19:12.353Z
Comments.Text: No. Debugging is off. Backtrace was on, but turning it off has made no difference.
Comments.UserDisplayName: Jern
Tags: <api><civicase><rest>
Title: CiviCRM 5.12.0 - Case API returning an Analyzer object containing XML and JSON. Only want JSON
ThreadText: # CiviCRM 5.12.0 - Case API returning an Analyzer object containing XML and JSON. Only want JSON
  
  (Asked by: username_0 on 2019-04-12)
  
  I had a working script set up to create cases in CiviCRM using REST.  
  <https://domain.com/administrator/components/com_civicrm/civicrm/extern/rest.php?entity=Case&action=create&json=1&version=3&key=xxxxxxxx&api_key=yyyyyyy>  
  (obviously with the correct payload etc). This worked fine. It returned the specified return:id etc in a nice small JSON. Now, the same script is failing because it can't parse the returned JSON. It seems that the API is now returning a Civi\CCase\Analyzer Object which contains the full case data as XML and as JSON. Is this change intentional? Is it documented anywhere? I'm wondering how to extract the JSON from the returned Analyzer object. Thanks.
  
  **Tags:** api, civicase, rest
  
  > **Comments:**
  > **username_1**: I'm not seeing any xml when I run it (on a drupal site). Is there something interesting about the way you run it? I tested with: curl -X POST '`http://site/civicrm/extern/rest.php?json=1`' -H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' --data 'entity=Case&action=create&api_key=12345&key=12345&contact_id=user_contact_id&case_type_id=1&subject=fromExternRest'  
  > **username_0**: Thanks. I tried the same thing as you, using curl, but the response I'm getting is a full dump of the newly-created Case in XML, including all associated activities and relationships, and then the JSON at the end of the output. I'm using Joomla, but I can't imagine that would make a difference? The script has been working fine for months, and I haven't done anything to it.  
  > **username_0**: The output starts like this, and goes on for a couple of thousand lines: Civi\CCase\Analyzer Object (     [caseId:Civi\CCase\Analyzer:private] => 775     [case:Civi\CCase\Analyzer:private] => Array         (             [id] => 775             [case_type_id] => 9             [subject] => fromExternRest             [start_date] => 2019-04-12             [status_id] => 1             [is_deleted] => 0             [created_date] => 2019-04-12 21:16:32             [modified_date] => 2019-04-12 21:16:32             [contact_id] => Array                 (                     [1] => 66  
  > **username_1**: Can you do a grep for var_dump or print_r? I'm thinking some debugging code was added in and is producing that output.  
  > **username_0**: OK, I couldn't see anything which looks suspect. But maybe you can spot something. The grep output is here - https://pastebin.com/nRCKcCky and here: https://pastebin.com/Hu82Atgi  
  > **username_1**: Hmm. Is debugging is turned on in the admin screen? Maybe it's causing some extra output?  
  > **username_0**: No. Debugging is off. Backtrace was on, but turning it off has made no difference.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2019-04-13. Score: 1 | Accepted answer
  
  Not a direct answer, but following on from the comments here are some more things you can try.
  
  1. If you haven't already, check the civicrm log. Maybe there is something helpful there. For example maybe there is a recoverable error happening but it dumps some output to stdout instead of the log, which during a REST call will be part of the response output.
  2. It's possible you have some code or an extension that implements the civicrm\_caseChange hook and then does some debug output. When looking or grepping be sure to look in any custom php and extension folders defined at admin -> system settings -> directories.
  3. Use `diff -r` or `kdiff` or something to compare your civicrm tree to a fresh unzipped 5.12 download to see if there's any differences.
  4. It's definitely print\_r output, but it might be coming indirectly from something that calls 'CRM\_Core\_Error::debug(' or 'CRM\_Core\_Error::debug\_var(', so can try grepping for that. Note I've included the opening bracket in the search string since I'm thinking that will give the least false matches.
  5. Try disabling some extensions one by one.
  6. Run a [php step-debugger](https://xdebug.org/docs/remote) to see exactly what step it gets output and where it's coming from. This will be time consuming, but you will almost certainly find it. If you can reproduce the problem on a local development copy of the site it will be slightly easier to set this up using that copy.
  
  > **Comments:**
  > **username_0**: Genius, thank you. The problem was caused by an extension which included a function implementing the caseChange hook (the function is very short, and just sends an email whenever a case is changed). I've pasted it here: https://pastebin.com/qH94m7EX. I'm not sure why it's outputting the contents of $analyzer, or how this gets into the response of the api create function. Anyway, we don't need it, so I have just commented it out, and the api response is now just the expected json. Thanks very much for your help.  
  > **username_1**: Great. By the way in that function if you just change `print_r($analyzer);` to `print_r($analyzer, true);` it will work as it seems like it was intended. Without the "true" it sends the output to stdout instead of returning a string, which is why you see it in the REST output.  
  > **username_2**: Another casualty of when debugging actually *causes* bugs.  
  
  ---
  
  