An all-optical format conversion (AOFC) scheme for the input 30 Gbit/s rectangular 8-ary quadrature amplitude modulation (8QAM) signal is proposed and numerically investigated based on phase-sensitive amplification (PSA) and nonlinear Mach-Zehnder interferometer (MZI). Firstly, the input rectangular 8QAM signal is orthogonal decomposed into the inphase and quadrature components based on PSA, respectively. The in-phase component is the 4-ary amplitude and phase shift keying (4APSK) signal and the quadrature component is the binary phase shift keying (BPSK) signal. Secondly, the converted 4APSK signal is transmitted into one piece of highly nonlinear fiber (HNLF) to obtain the phase-distorted two-amplitude and two-phase (2A-2P) signal based on the self-phase modulation (SPM) effect. After adjusting the power of the 2A-2P signal, it is injected into one nonlinear MZI to eliminate the amplitude difference of the inner and the outer rings of the 2A-2P signal. The 2A-2P signal can be converted into the regular quadrature phase shift keying (QPSK) signal by the nonlinear MZI with phase preservation. Thirdly, the converted BPSK and QPSK signals are coherently superposed in one 3-dB optical coupler (OC) to get the aggregated rectangular 8QAM signal and other types of 8QAM signals. The proposed scheme can also be extended to realize the AOFC from the 16-ary quadrature amplitude modulation (16QAM) signal to two QPSK signals. The constellation diagrams, amplitude and phase histograms, error vector magnitude (EVM) and bit error rate (BER) of the relevant optical signals are measured to evaluate the system performance. The proposed scheme can be equipped with the optical gateway to enable all-optical interconnection of optical networks with different modulation formats.