Zhang Jiazhen was born in 666, during the reign of Emperor Gaozong. His family was from Pu Prefecture (蒲州, roughly modern Yuncheng, Shanxi), and traced its ancestry to the Jin Dynasty (265-420) chancellor Zhang Hua and his First Son (張祎) (張華 → 張祎 → 張輿 → 次惠 → 安之 → 宏策 ( 張緬 →...張九齡 Zhang Jiuling) → 絢 → 吒子 → 長度 → 俊興 → 思義 → 張俊義). who was originally from Fanyang (范陽, in modern Beijing), but his great-great-grandfather Zhang Zizha (張子吒) served as the secretary general of Hedong Commandery (河東, roughly modern Yuncheng, later converted into Pu Prefecture) for Tang Dynasty's predecessor Sui Dynasty, and therefore relocated his family to Hedong. Zhang Jiazhen's great-grandfather Zhang Changdu (張長度), grandfather Zhang Junxing (張俊興), and father Zhang Siyi (張思義) all served as minor officials for Tang. He had at least one younger brother, Zhang Jiayou (張嘉祐), and as Zhang Siyi died early, Zhang Jiazhen and Zhang Jiayou supported each other in their youths.
Zhang Jiazhen passed the imperial examinations in his youth and was made the magistrate of Pingxiang County (平鄉, in modern Xingtai, Hebei), but was removed from office for an offense unspecified in historical accounts. He then returned home to Pu Prefecture. During the Chang'an era (701-705) of Emperor Gaozong's wife Wu Zetian, there was an occasion when the imperial censor Zhang Xunxian (張循憲) was ordered to examine Hedong Circuit (河東道, roughly modern Shanxi), when he encountered some cases that were difficult for him to decide. He thus asked the local officials, "Is there anyone here who is intelligent whom I can consult?" A local official recommended Zhang Jiazhen, and Zhang Xunxian consulted him. Zhang Jiazhen surprised Zhang Xunxian with his ability to analyze the situation and come up with the correct resolutions. He thus had Zhang Jiazhen draft his report to Wu Zetian as well. After Zhang Xunxian returned to the capital Luoyang, Wu Zetian was impressed by the quality of the report. Zhang Xunxian informed her that it was Zhang Jiazhen who drafted it for him, and offered to give his office to Zhang Jiazhen. She responded, "Do I not have an office for the capable?" She summoned Zhang Jiazhen to Luoyang and met with him personally. She was impressed with him, and thus made him an imperial censor; she also promoted Zhang Xunxian for his ability to find Zhang Jiazhen. Zhang Jiazhen subsequently successively served as a low-level official at the ministry of defense (兵部員外郎, Bingbu Yuanwailang), when he became known for his abilities; Zhongshu Sheren (中書舍人), a mid-level official at the legislative bureau of government (中書省, Zhongshu Sheng); the commandant at Liang Prefecture (梁州, roughly modern Hanzhong, Shaanxi) and then Qin Prefecture (秦州, roughly modern Tianshui, Gansu); and then the secretary general at Bing Prefecture (并州, roughly modern Taiyuan, Shanxi). He became known for strictness in his governance, and his subordinates feared him.
Early in the Kaiyuan era (713-741) of Wu Zetian's grandson Emperor Xuanzong, Zhang Jiazhen, who was then still serving as the secretary general at Bing Prefecture, was in then-capital Chang'an on one occasion to report on his prefecture. Emperor Xuanzong had heard of his capabilities and therefore praised him. Zhang Jiazhen took the opportunity to request that his brother Zhang Jiayou, who was then the secretary general at Shan Prefecture (鄯州, roughly modern Haidong Prefecture, Qinghai), be moved to a closer location to him, as he missed his brother. Emperor Xuanzong praised him for his brotherly love and made Zhang Jiayou the prefect of Xin Prefecture (忻州, roughly modern Xinzhou, Shanxi), close to Zhang Jiazhen's post at Bing Prefecture.
In 718, with a group of Eastern Tujue people having submitted to Tang in the aftermaths of the death of the Eastern Tujue khan Ashina Mochuo, Zhang Jiazhen suggested that a military base be established to help curb in the Eastern Tujue people. Pursuant to his suggestion, Tianbing Base (天兵軍) was established at Bing Prefecture, and Zhang was put in command of the base. In 718, Zhang was in Chang'an when there were accusations made that he was overly luxurious and corrupt while at Bing Prefecture. The chief imperial censor Wang Jùn thus indicted him, but after investigation, Zhang Jiazhen was cleared. Emperor Xuanzong considered executing the accuser as punishment for the false accusation, but Zhang pointed out that such an execution would have a chilling effect on the report of wrongdoing. Emperor Xuanzong thus only exiled the accuser, and he came to believe that Zhang was faithful and capable of greater duties, informing Zhang that one day he would likely be chancellor. Zhang responded:
When Ma Zhou [a chancellor during the reign of Emperor Xuanzong's great-grandfather Emperor Taizong] was poor and met the emperor, he was still young and strong. Emperor Taizong retained him and used his abilities, and yet lost Ma at age 50. If he had started using Ma at a later time, he would not have received Ma's service. Your Imperial Majesty does not consider me insolent and want to use me. Yet, if you delay, I may be too old to serve you. Further, it is rare that people can live to be 100. I often fear that I would die first in a ditch. If I were able to serve Your Imperial Majesty, I would surely not disappoint you.
Emperor Xuanzong instead responded, "Just go back right now; I will surely recall you soon." In 720, when Emperor Xuanzong was set to remove the chancellors Song Jing and Su Ting and was considering whom to make chancellor, he thought of Zhang Jiazhen, but forgot Zhang Jiazhen's name. He thus asked the official Wei Kang (韋抗), "I can remember a general to the north who is capable; his name is Zhang, and his personal name has two characters. Can you think of it for me?" Wei thought it was Zhang Qiqiu (張齊丘), who was then the military governor (jiedushi) of Shuofang Circuit (朔方, headquartered in modern Yinchuan, Ningxia), and so Emperor Xuanzong had an edict drafted up, making Zhang Qiqiu chancellor. That night, however, when Emperor Xuanzong was reviewing files, he ran across Zhang Jiazhen's name and remembered him. He thus modified the edict to commission Zhang Jiazhen instead as Zhongshu Shilang (中書侍郎), the deputy head of the legislative bureau, with the designation Tong Zhongshu Menxia PIngzhengshi (同中書門下平章事), making him a chancellor de facto, along with Yuan Qianyao. Later that year, Zhang was made Zhongshu Ling (中書令) -- the head of the legislative bureau and a post considered one for a chancellor. As chancellor, Zhang was said to be capable and energetic, but self-important and inflexible; he was criticized by popular sentiment for those faults. He recommended the junior officials Miao Yansi (苗延嗣), Lü Taiyi (呂太一), Yuan Jiajing (員嘉靜), and Cui Xun (崔訓) for promotions and entrusted them with many important tasks.
In 722, when Emperor Xuanzong visited Luoyang, an official at the Luoyang County government, Wang Jūn (王均, note different tone than the censor who indicted Zhang), had been building a mansion for Zhang, hoping to ingratiate him enough to be made an imperial censor. However, Wang Jūn was accused of corruption and set to be sentenced to death by caning. Zhang had Wang Jūn put to death as quickly as possible to avoid any taint, and then blamed Wei Kang, who was then chief imperial censor, and Wei Kang's deputy Wei Xuxin (韋虛心), and had them demoted. Later that year, the official Jiang Jiao (姜皎) was accused of leaking secret discussions with Emperor Xuanzong (in which Emperor Xuanzong talked with him about the possibility of deposing his wife Empress Wang. Zhang and Empress Wang's brother Wang Shouyi (王守一) both advocated that Jiang be caned and then exiled. Emperor Xuanzong did so, and Jiang died on the way to his place of exile. Soon thereafter, Pei Zhouxian (裴伷先) the commandant at Guang Prefecture (廣州, roughly modern Guangzhou, Guangdong) was accused of corruption, and Zhang again advocated caning him. However, Zhang Shuo, who had been made a chancellor as well, argued that public caning is inappropriate for high-level officials, and Emperor Xuanzong agreed. After the meeting with Emperor Xuanzong was over, Zhang Jiazhen, displeased, asked Zhang Shuo, "Why did you have to go into such deep talk?" Zhang Shuo responded:
Chancellors come and go. If even high-level officials can be caned, then perhaps one day we will be caned as well. I did not speak those words just for Pei Zhouxian, but for all learned people of the realm.
Meanwhile, Zhang Shuo and Zhang Jiazhen had not been on good terms, because Zhang Shuo, who ranked below Zhang Jiazhen in the precedence of chancellors, had previously served as Zhang Jiazhen's superior while serving as deputy minister of defense, and therefore resented Zhang Jiazhen for not showing him more respect. Meanwhile, Zhang Jiazhen's brother Zhang Jiayou had been made a high-ranked general, but in 723 was accused of corruption. At Zhang Shuo's suggestion, Zhang Jiazhen wore plain-colored clothes and waited outside the palace for punishment, to show remorse. Instead of escaping punishment as Zhang Jiazhen hoped, however, Zhang Jiazhen, without getting another audience with Emperor Xuanzong, was demoted to be the prefect of You Prefecture (幽州, roughly modern Beijing). Zhang Shuo then replaced him as Zhongshu Ling, drawing hatred from Zhang Jiazhen, who commented, "There can be two people serving as Zhongshu Ling. Why did he have to squeeze me out?" In 724, Zhang Jiazhen was recalled to serve as minister of census (戶部尚書, Hubu Shangshu), as well as secretary general at Yi Prefecture (益州, roughly modern Chengdu, Sichuan). Emperor Xuanzong had Zhang Jiazhen join the chancellors for a banquet. Zhang Jiazhen, still resenting Zhang Shuo, cursed Zhang Shuo when they were both at the banquet, requiring Yuan Qianyao and Wang Jùn to step in to moderate between the two.
Later in 724, Wang Shouyi was accused of using witchcraft to try to regain Emperor Xuanzong's favor for his sister Empress Wang. Empress Wang was deposed, and Wang Shouyi was first exiled and then ordered to commit suicide. Zhang Jiazhen, because of his association with Wang Shouyi, was demoted to be the prefect of Tai Prefecture (臺州, roughly modern Taizhou, Zhejiang). However, he was eventually recalled to serve successively as minister of public works (工部尚書, Gongbu Shangshu) and then prefect of Ding Prefecture (定州, roughly modern Baoding, Hebei). He was also created the Marquess of Hedong. After he got to Ding Prefecture, on one occasion, he commissioned a stele for a temple dedicated to the god of Mount Heng, and personally wrote the text on the stele, described to be very beautiful in form. As there were much money donations made to the temple, he believed himself to be responsible for those donations, and so took a small part of it.
In 729, Zhang requested to be allowed to go to Luoyang on account of illness. Emperor Xuanzong agreed. Once Zhang got to Luoyang, he was no longer able to see, and Emperor Xuanzong sent imperial physicians to treat him. He died in the fall that year and was given posthumous honors. Zhang Jiazhen's son Zhang Yanshang and grandson Zhang Hongjing later served as chancellors for Emperor Dezong and Emperor Xianzong, respectively.
It was said that although Zhang served in many important offices, he never spent time managing his estate. When he was at Ding Prefecture, some relatives suggested that he should begin to do so. Zhang responded:
I was fortunate to serve in important offices and once having served as chancellor. As long as I live, I do not fear hunger. If I were to be charged with a crime, all riches will be worthless. I have seen many officials who managed large estates, only for their useless descendants to spend away once they were dead. Their work was all for vain.
Those who heard him were impressed by the analysis.