Because of its proximity and the large size of its black hole, M87 is one of the best targets for studying the launching mechanism of active galactic nucleus jets. Currently, magnetic fields are considered to be an essential factor in the launching and accelerating of the jet. However, current observational estimates of the magnetic field strength of the M87 jet are limited to the innermost part of the jet (<~100r_s_) or to HST-1 (~10^5^r_s_). No attempt has yet been made to measure the magnetic field strength in between. We aim to infer the magnetic field strength of the M87 jet out to a distance of several thousand r_s_ by tracking the distance-dependent changes in the synchrotron spectrum of the jet from high-resolution very long baseline interferometry observations. In order to obtain high-quality spectral index maps, quasi-simultaneous observations at 22 and 43GHz were conducted using the KVN and VERA Array (KaVA) and the Very Long Baseline Arra (VLBA). We compared the spectral index distributions obtained from the observations with a model and placed limits on the magnetic field strengths as a function of distance. The overall spectral morphology is broadly consistent over the course of these observations. The observed synchrotron spectrum rapidly steepens from alpha_22-43GHz_~-0.7 at ~2mas to alpha_22-43GHz_~-2.5 at ~6mas. In the KaVA observations, the spectral index remains unchanged until ~10mas, but this trend is unclear in the VLBA observations. A spectral index model in which nonthermal electron injections inside the jet decrease with distance can adequately reproduce the observed trend. This suggests the magnetic field strength of the jet at a distance of 2-10mas (~900r_s_~4500r_s_ in the deprojected distance) has a range of B=(0.3-1.0G)(z/2mas)^-0.73^. Extrapolating to the Event Horizon Telescope scale yields consistent results, suggesting that the majority of the magnetic flux of the jet near the black hole is preserved out to ~4500r_s_ without significant dissipation.