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