Engine swap 4,7 to 5,2!

My son bought a 2001 Dakota SLT w/4,7 Magnum. The engine is shot after 236 000 miles! Now he found a nice 5,2 Magnum from a 1997 or 1998 Jeep Grand Cherokee with 12000 miles on it. Will that swich be ok? Any problems etc? The seller is asking usd 500 for the 5,3 M.

Since I'm into older stuff I hope to get some great answers!