Remova o espaço e a linha do JSON no PHP

$before = '{ "key": "value with whitespaces to maintain" }';
$after  = json_encode(json_decode($before));
Ankur