Johannesburg is notorious for being a dangerous city—it's quite common to hear about serious crimes such as armed robbery and murder. That said, it's safe for visitors who avoid dangerous areas and take reasonable precautions. Do not leave bags or valuables visible in a car, and keep the doors locked, even while driving (to minimize the risk of smash-and-grab robberies or carjackings); don't wear flashy jewelry or carry large wads of cash or expensive equipment. Don’t visit a township or squatter camp on your own. Unemployment is rife, and foreigners are easy pickings. If you wish to see a township, check with reputable companies, which run excellent tours and know which areas to avoid. The Apartheid Museum and Constitution Hill within the city and the Cradle of Humankind just outside are perfectly safe to visit on your own.
If you drive yourself around the city, it’s safest to keep your doors locked and windows up, and to not leave valuables such as bags, cameras, or phones on the seat or visible. That said, it is safe to drive yourself around Johannesburg. If you prefer, though, you could order a car service or transportation from your hotel for trips in and around the city.