How to handle malformed response from WP REST API?

If you are creating classes, the first thing in the construct would be this. Or you can drop it in with an action as early as possible. Maybe plugins_loaded.

/*
     * If WP DEBUG is not on do NOT return any php warning, notices, and/or fatal errors.
     * Well If it is a fatal error then this return is FUBAR anyway...
     * We do this because some badly configured servers will return notices and warnings switch get prepended or appended to the rest response.
     */
    if( defined('WP_DEBUG') ){
        if( false === WP_DEBUG ){
            error_reporting(0);
        }
    }