We investigate nucleosynthesis inside jets in a gamma ray bursts (GRB). We have calculated detailed composition of magnetically driven jets related to GRBs with post-processing calculation, which is based on long-term, magneto-hydrodynamic simulations of a rapidly rotating massive star of 40M ⊙ during core collapse. We follow abundance evolution of about 4000 nuclides inside the jets from the collapse phase to the ejection phase through the jet generation phase with a large nuclear reaction network. We find that the r-process successfully operates inside the jets, so that U and Th are synthesized abundantly. Abundance pattern inside the jets is similar compared to that of r-elements in the solar system. Heavy neutron-rich nuclei ∼ 0.001M⊙ can be ejected through the jets. Furthermore, we find that p-nuclei are produced without seed nuclei: not only light p-nuclei, such as 74Se, 78Kr, 84Sr, and 92Mo, but also heavy p-nuclei, 113In, 115Sn, and 138La, can be abundantly synthesized in the jets. The amounts of p-nuclei in the ejecta are much greater than those in core collapse supernovae (SNe). In particular, 92Mo, 113In, 115Sn, and 138La deficient in core collapse SNe, are significantly produced in the ejecta.