With the version of CakePHP I'm forced to work with, this is handled by passing a $_serialize variable to the view.
// html view gets access to $var1 and $var2
// same endpoint with '.json' at the end only gets $var1
set(['var1' => ..., 'var2' => ..., '_serialize' => ['var1']]);