A study of the production of prompt J/$\psi$ mesons as fragmentation products of jets in proton-proton collisions at $\sqrt{s} =$ 8 TeV is presented. The analysis is based on data corresponding to an integrated luminosity of 19.1 fb$^{-1}$ collected with the CMS detector at the LHC. For events with at least one observed jet, the angular separation between the J/$\psi$ meson and the jet is used to test whether the J/$\psi$ meson is a jet fragment. The analysis shows that most prompt J/$\psi$ mesons with energy above 15 GeV and rapidity $|y|<$ 1 are fragments of jets with pseudorapidity $|\eta_{\text{jet}}| <$ 1. The differential distributions of the jet fragmentation probability as a function of jet energy for a fixed J/$\psi$ energy fraction are compared to a theoretical model using the fragmenting jet function approach. The data agree best with fragmenting jet function calculations that use a long-distance matrix element parameter set in which prompt J/$\psi$ mesons are unpolarized. This technique demonstrates a new way to test predictions for prompt J/$\psi$ production using nonrelativistic quantum chromodynamics.