In this paper we investigate the detectability of the molecular oxygen in icy dust grain mantles towards astronomical objects. We present a systematic set of experiments with O_2_-H_2_O ice mixtures designed to disentangle how the molecular ratio affects the O_2_ signature in the mid- and near-infrared spectral regions. All the experiments were conducted in a closed-cycle helium cryostat coupled to a Fourier transform infrared spectrometer. The ice mixtures comprise varying thicknesses from 8x10^-3^ to 3um. The absorption spectra of the O_2_-H_2_O mixtures are also compared to the one of pure water. In addition, the possibility to detect the O_2_ in icy bodies and in the interstellar medium is discussed. We are able to see the O_2_ feature at 1551cm^-1^ even for the most diluted mixture of H_2_O:O_2_=9:1, comparable to a ratio of O_2_/H_2_O=10% which has already been detected in situ in the coma of the comet 67P/Churyumov-Gerasimenko. We provide an estimate for the detection of O_2_ with the future mission of the James Webb Space Telescope (JWST).