The production of $J/psi$ mesons in jets is studied in the forward region of proton-proton collisions using data collected with the LHCb detector at a center-of-mass energy of 13 TeV. The fraction of the jet transverse momentum carried by the $J/psi$ meson, $z equiv p_{rm T}(J/psi)/p_{rm T}({rm jet})$, is measured using jets with $p_{rm T}({rm jet}) > 20$ GeV in the pseudorapidity range $2.5 < eta({rm jet}) < 4.0$. The observed $z$ distribution for $J/psi$ mesons produced in $b$-hadron decays is consistent with expectations. However, the results for prompt $J/psi$ production do not agree with predictions based on fixed-order non-relativistic QCD. This is the first measurement of the $p_{rm T}$ fraction carried by prompt $J/psi$ mesons in jets at any experiment.