The magnetic properties of a substance can be determined by examining its molecular orbital configuration, If it has unpaired electrons, then the substance is paramagnetic and if all electrons are paired, the substance is then diamagnetic.
Molecular orbital configuration of O2 molecule : σ1s2σ⋆1s2σ2s2σ⋆2s2σ2pz2π2px2≡π2py2π⋆2px1≡π⋆2y1 O2 molecule has 2 unpaired electrons, so it is paramagnetic
In CsO2 molecule, super oxide ion O2− has one unpaired electron, therefore it is paramagnetic. O2−ion:σ1s2σ⋆1s2σ2s2σ⋆2s2σ2pz2π2px2≡π2py2π⋆2px2≡π⋆2y1 N2 molecule is isoelctronic with CO , there are no unpaired electrons in N2 molecule . N2,CO,C2,BaO2 and CO2 are diamagnetic due to the absence of unpaired electrons.