James Gray, son of William S. Gray and his wife Maria McCarthy, resided on the Witwatersrand from 1889. He was sent to Scotland for his education and, after attending the Allan Glen's Boys School in Glasgow, studied chemistry at the Royal Technical College, Glasgow, qualifying as an associate of the Institute of Chemistry of Great Britain and Ireland in 1902. Upon his return to South Africa he worked for a while as a mine surveyor but in about 1904 became chief assistant to Alexander Heymann*, a leading analytical and consulting chemist on the Witwatersrand. However, in 1905 he worked as analytical chemist at the Langlaagte Estate and Gold Mining Company, Johannesburg. In 1912 he started his own practice in Simonds Street (later in Main Street), Johannesburg, which he continued until his retirement in 1948.
His publications on chemical subjects included the following articles in the Journal of the Chemical, Metallurgical and Mining Society of South Africa: "The influence of moist air on quicklime" (1909, Vol. 9), "The assay of tin ores" (1909/10, Vol. 10), "The destruction of cyanide" (as co-author with J. Moir; 1909/10, Vol. 10), and "The determination of gold in the presence of iridium and allied metals in materials such as black sand" (with C. Toombs*; 1913/14, Vol. 14). He also published a paper on the distribution of the forms of sulpher in Transvaal coal in the Journal of the South African Chemical Institute (1922).
Gray played an active part in the advancement and promotion of science. He became an associate of the (British) Institute of Chemistry (later the Royal Institute of Chemistry), a member of the (British) Society of Chemical Industry (1904), and was later elected a Fellow of the Institute of Chemistry. In South Africa he became a member of the Chemical, Metallurgical and Mining Society of South Africa in 1904, serving on its council by 1911 and as its president for 1919/20. His presidential address dealt with "The position of the chemist in South Africa" and was published in the society's Journal. In 1917 he became the first person to receive the Government Certificate of Competency for assayers, and during 1917-1920 and 1923-1926 was one of the commission of examiners for the certificate. He joined the South African Association for the Advancement of Science in 1907, served as its honorary treasurer from 1921 to 1953, as president of Section B for 1933, as vice-president of the association during 1934-1936 and 1939/40, and as president for 1940/1. In 1912 he played a leading role in the foundation of the South African Association of Analytical Chemists (from 1921 the South African Chemical Institute), served on its council as honorary secretary for most of the period 1912-1937, and as president for 1922/3. In 1928 he was president of the Associated Scientific and Technical Societies of South Africa. The next year he served on the executive committee that arranged the second visit of the British Association for the Advancement of Science to South Africa.
In addition to his busy professional life Gray was active in municipal and political affairs. For 25 years he was a member of the consultative committee of the Johannesburg Public Library and a member of the Johannesburg Rotary Club, serving as president of the latter for 1926/27. He was also president of the Rand Pioneers in 1932 and 1936. From 1941 he was a member of the Johannesburg City Council and was mayor of Johannesburg around 1947. From 1943 to 1950 he was a member of the Transvaal Provincial Council. In December 1916 he married Ethel L. Anderton, with whom he had a son and a daughter. The son, Douglas J.S. Gray, also became a chemist. Gray senior compiled a Roll of Rand Pioneers, which is housed in the Johannesburg Public Library. His wife studied the history of the discovery of gold on the Witwatersrand in the National Archives, Pretoria, on the basis of which they wrote Payable gold; an intimate record of the history of the discovery of the payable Witwatersrand gold fields and Johannesburg in 1886 and 1887 (Johannesburg, 1937, 286p) and A history of the discovery of the Witwatersrand goldfields (Johannesburg, 1940). Gray suffered a stroke in October 1952 and died as a mental patient after a long illness.