A study of the production of prompt J/psi mesons contained in jets in proton-proton collisions at root 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 part of the jet. The analysis shows that most prompt J/psi mesons having energy above 15 GeV and rapidity vertical bar y vertical bar < 1 are contained in jets with pseudorapidity vertical bar eta(jet)vertical bar < 1. The differential distributions of the probability to have a J/psi meson contained in a jet 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 predicted to be unpolarized. This technique demonstrates a new way to test predictions for prompt J/psi production using nonrelativistic quantum chromodynamics.