James S. Gray was born in February 1843 in Maine to James and Emma Gray. His father was a farmer who owned $1,500 of real estate and $500 of personal property in 1860. Gray grew up and attended school in Standish, Maine. He enlisted in the Union army on September 29, 1862, and mustered in as a private in Company K of the 25th Maine Infantry later that day.
The regiment took part in the defense of Washington, D.C., and Gray mustered out on July 10, 1863, when his nine-month term of enlistment expired. He re-enlisted in the Union army several months later, mustering in as a private in the 1st District of Columbia Cavalry on February 19, 1864. Confederate forces captured him on June 29, 1864, and he spent the following weeks in Andersonville Prison. He died there on August 15, 1864.