Doctors detected the need for the operation during an annual check up in June and the operation was scheduled for the end of August, a spokesman for the royal palace told AFP.
“It does not seem like it is a serious case,” the spokesman said, adding the 81-year-old had “led a normal life” since he was told he needed surgery.
The royal palace did not specify what medical condition would be treated. The operation will be carried out at a private hospital at a Madrid suburb.
Juan Carlos, who helped smooth Spain's transition to democracy in the 1970s after the Francisco Franco dictatorship, abdicated in favour of his son Felipe in 2014.
Despite having retired from public life, he has continued to be spotted in public at bullfights in Madrid and at a sailing competition in Finland.
He underwent a knee operation last year and has had multiple hip operations.