Gong'an or crime-case fiction (Chinese: 公案小说) is a subgenre of Chinese crime fiction involving government magistrates who solve criminal cases. The Judge Dee and Judge Bao stories are the best known examples of the genre.
There are no surviving works of Song gong'an, a genre of Song Dynasty puppetry and oral performances. Judge Bao stories based on the career of Bao Zheng, a common protagonist of gong'an fiction, first appeared during the Yuan Dynasty. Bao was a historical figure who worked for Emperor Renzong of Song as a magistrate. Accounts of his life were recorded in historical documents that later inspired the mythological Judge Bao of gong'an fiction.
The Circle of Chalk (Chinese:) is a Yuan zaju play that recounts a Judge Bao criminal case. The popularity of Judge Bao performances contributed to the success of written gong'an novels published in the 16th and 17th centuries. The oldest collection of Judge Bao stories is the Bao Longtu Baijia Gong'an, the Hundred Cases of Judge Bao, also included in the Ming Dynasty Bao Gong An (Chinese:).
The popularity of gong'an novels diminished in the early years of the Qing Dynasty. It was not until the latter years of the dynasty that the genre experienced a resurgence. Thematically, the gong'an works of the Qing Dynasty mixed elements of traditional gong'an fiction with the wuxia martial arts genre. Qing Judge Bao stories were widespread in every medium, from operas to folk performances and novels. Other magistrates like Judge Peng and Judge Li were also the subject of gong'an works. Shi Gong'an, Judge Shi's Cases, was published in 1798.