The officers were in the area of San Antonio Street and Sunset Avenue when they spotted the boy playing with some kids, San Jose police spokesman Jermaine Thomas said.
"The boy was choking and actually turning blue," Thomas said. He said the officers "tried patting the child on the back," but that didn't work.
One of the officers then performed the Heimlich maneuver on the boy, and the candy dislodged from his throat, according to Thomas.
He said the boy was released to his parents and didn't need to go to a hospital.