Jets containing a prompt J$/\psi$ meson are studied in lead-lead collisions at a nucleon-nucleon center-of-mass energy of 5.02 TeV, using the CMS detector at the LHC. Jets are selected to be in the transverse momentum range of 30 $\lt$$p_\mathrm{T}$$\lt$ 40 GeV. The J$/\psi$ yield in these jets is evaluated as a function of the jet fragmentation variable $z$, the ratio of the J$/\psi$$p_\mathrm{T} $ to the jet $p_\mathrm{T}$. The nuclear modification factor, $R_\mathrm{AA}$, is then derived by comparing the yield in lead-lead collisions to the corresponding expectation based on proton-proton data, at the same nucleon-nucleon center-of-mass energy. The suppression of the J$/\psi$ yield shows a dependence on $z$, indicating that the interaction of the J$/\psi$ with the quark-gluon plasma formed in heavy ion collisions depends on the fragmentation that gives rise to the J$/\psi$ meson.