Pulsar timing observations precisely test general relativity. Recently, the hierarchical triple system PSR J0337 + 1715 has placed new constraints on the existence of a fifth force from violation in the strong equivalence principle. Many alternative gravity theories exist with massive (pseudo-)scalar fields to explain a variety of phenomena from the accelerating expansion of the Universe at large scales to the QCD strong CP problem at small scales. We here develop a generic formalism for the fifth force effect in theories involving massive scalar fields arising from e.g. string theory. With PSR J0337 measurements, we find the strongest bound on the simplest theory with a massive scalar field beyond general relativity and derive new constraints in other theories with axions, dark matter mediators, and higher-curvature corrections. These results show that the triple system J0337 provides a stringent test for massive scalar fields.