Just a thought to ponder on Maza, which may have led to the confusion of the surnames of Gray and Anderson.
Annette posted earlier the 1861 census entry for Mary Gray with two children down as Robertson and John showing as Gray. Mary, mother, was showing as unmarried....
Likely John's birth was illegitimate. Not uncommon for illegitimate children to go by the surname of their reputed father, and often sway around with surnames. In this case you have the use of the name of John Gray Anderson, Gray being mother and Anderson perhaps his reputed father's surname. Not uncommon to do this at that time.
Can't easily see John Gray Anderson's birth on family search so maybe he was born in 1854, the year before the start of official registration in Scotland?
Monica
