Strip extraneous whitespace in API JSON responses (bug 914876)

r? @mattbasta @diox @cvan