We have developed a flexible framework for constructing Jastrow factors which allows for the introduction of terms involving arbitrary numbers of particles. The use of various three- and four-body Jastrow terms in quantum Monte Carlo calculations is investigated, including a four-body van der Waals-like term, and anisotropic terms. We have tested these Jastrow factors on one- and two-dimensional homogeneous electron gases, the Be, B, and O atoms, and the BeH, H2O, N2, and H2 molecules. Our optimized Jastrow factors retrieve more than 90% of the fixed-node diffusion Monte Carlo correlation energy in variational Monte Carlo for each system studied.