Near-infrared spectra of compact planetary nebulae