During the episode, a character played by actor Nathan Lane is riding in a New York City taxi. De Blasio loudly extolls the city's virtues in a commercial shown on a loop on the cab's back-seat television.
This prompts Lane to ask his cab driver to turn off the video, saying "the mayor won't stop talking."
It's de Blasio's first acting job since taking office. He has described himself as an "intense" fan of the show.
"The Good Wife" is loosely inspired by another New York Democrat, former Gov. Eliot Spitzer.