You can find the full payload specification here.
This decoder is written in Java Script and may be freely used as example code. To inspect the code, open this link and inspect the Java Script source. Usually this is done with F12 in your browser. A version suitable for use with The Things Network is attached at the bottom of the page.