Immigration at JNB can be a bit of a Zoo in the morning hours when most flights arrive. But 5 hours are plenty to go thru immigration and back in.
Try to spend a day there. Take the train from the airport (frequent, takes around 30 min) to Sandton (last stop). Many hotels very close to the train station, large shopping mall etc. Lots of things to see/do. That area is safe.