I had an Optima (group size 34) in my old Jeep and was also wondering what size the JK had...couldn't find an answer so I just tried it - it fit!
FYI for anyone considering an Optima - the Optima's posts are closer together than the stock battery so the connectors work better if they are adjusted to an 90 angle verus straight.
Regarding OP question:
It looks like W and H would be OK, L might be a problem. The 31 looks like it is about 2 3/4" longer than the 34. There only about 3/4 to 1" space and each side of the 34 BUT the plastic has some give so you might be able to squeeze it in there.... The JK uses clamps at the base of the battery for retention so the new battery would need to be compatible (have the little ridges).
Hope this helps...