I like to move it move it
Groovy, 656 bytes

That was too long...

i={println"Invalid map."
System.exit(1)}
m=[]
q=System.in.newReader()
r=q.readLine()
while(r!=''){m&lt;&lt;r
r=q.readLine()}
o=m[0].size()
m.each{if(it.size()!=o)i()}
f=[0]*4
m.eachWithIndex{l,n-&gt;s=l.indexOf('S')
e=l.indexOf('E')
if(s!=-1){f[0]=s;f[1]=n}
if(e!=-1){f[2]=e;f[3]=n}}
v=[]
t={x,y,d-&gt;if(d.contains([x,y])|y&gt;=m.size()|x&gt;=o|x&lt;0|y&lt;0)return
a=m[y][x]
def p=d+[[x,y]]
if(a=='E')v=p
if(a=='J'|a=='0'|a=='S'){t(x-1,y,p)
t(x+1,y,p)
t(x,y+1,p)
t(x,y-1,p)}}
t(f[0],f[1],[])
if(!v)i()
o=0
p=''
v.inject{t,s-&gt;
c=m[s[1]][s[0]]
k=[t[0]-s[0],t[1]-s[1]]
z=[[0,1]:0,[1,0]:1,[0,-1]:2,[-1,0]:3][k]
p+=((((o-z)==0)?'':(z&gt;0?'R':'L'))+(c=='J'?'M':'')+'F')
o=z
s}
println p


Output for the maze:

RFFLFRFMFLFRFLFF


Ungolfed:

invalid = {
    println "Invalid map."
    System.exit(1)
}
map = """01001E
010110
000P00
1110J1
S00111""".split('\n')

//map = [""]// TODO remove this, this is type checking only
//map.remove(0)
//reader = System.in.newReader()
//line = reader.readLine()
//while (line != '') {
//    map &lt;&lt; line.replace('P','1')
//    line = reader.readLine()
//}

size = map[0].size()
map.each {if(it.size() != size) invalid()}

startAndEnd = [0,0,0,0]
map.eachWithIndex {it, idx -&gt; s=it.indexOf('S');e=it.indexOf('E');
    if(s!=-1){ startAndEnd[0]=s; startAndEnd[1]=idx}
    if(e!=-1){ startAndEnd[2]=e; startAndEnd[3]=idx}}

def validPath = []

testMove = {x, y, visited -&gt;// visited is an array of x y pairs that we have already visited in this tree
    if (visited.contains([x,y]) || y&gt;=map.size() || x&gt;=size || x&lt;0 || y&lt;0)
        return;

    def valueAtPos = map[y][x]
    def newPath = visited + [[x,y]]

    if (valueAtPos == 'E') validPath = newPath
    if ((valueAtPos == 'J' || valueAtPos == '0' || valueAtPos == 'S') &amp;&amp; !validPath) {
        testMove(x-1, y, newPath)
        testMove(x+1, y, newPath)
        testMove(x, y+1, newPath)
        testMove(x, y-1, newPath)
    }
}
if (!validPath) invalid()
testMove(startAndEnd[0],startAndEnd[1], [])

println validPath

orintation = 0
path = ''
validPath.inject {first, second -&gt;
    def chr = map[second[1]][second[0]]
    def sub = [first[0]-second[0],first[1]-second[1]]
    println "acc:$first, second:$second"
    def newOrin = [[0,1]:0, [1,0]:1, [0,-1]:2, [-1,0]:3][sub]
    path += ((((orintation - newOrin)==0)?'':(newOrin&gt;0?'R':'L')) + (chr=='J'?'M':'') + 'F')
    orintation = newOrin
    second
}
println "path: $path"


I will try this again in python soon to see if I can shorten it further.