The King James Version and the Tanakh both say in Zechariah 12:10, "and they shall look upon me whom they have pierced." When John is writing in John 19:37 and quotes Zechariah 12:10, he has changed it to say, "They shall look on him (instead of me) whom they pierced."
John understands Zechariah 12:10 to be a Literal Prophecy plus Literal Fulfillment.
John is convinced that Jesus is God Himself appearing and living among Israel as a man, as the Messianic person. John then communicates his understanding of the scene he witnessed when Jesus was pierced by the Roman spear. He knew that the Messianic person had to be pierced according the Zechariah 12:10. He believes that Jesus is the Messianic person. When he sees Jesus pierced by the Roman soldier, he understands that moment to be a literal fulfillment of what was predicted in Zechariah 12:10......
John is not alone in his understanding that the Messianic person is being referred to here. Ancient Jewish sages carried the same understanding. Here are a few quotes found in rabbinic literature:
Babylonian Talmud Sukkah 52a:
It's well according to him who explains that the cause (of the mourning) is the slaying of the Messiah the son of Joseph, since that well agrees with the Scripture verse: 'And they shall look upon me, whom they have pierced; and shall mourn for him, as one mourneth for his only son'. 1