CiviCRM 5.12.0 - Case API returning an Analyzer object containing XML and JSON. Only want JSON
Not a direct answer, but following on from the comments here are some more things you can try.


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.
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.
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.
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.
Try disabling some extensions one by one.
Run a php step-debugger 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.