Justice Cynthia Kern of Manhattan state Supreme Court issued the ruling Monday. It finds that a decision to release the ratings with the teachers' names attached was not arbitrary or capricious under the law.
The judge denied a petition by the United Federation of Teachers to keep the teachers' names private.
UFT President Michael Mulgrew said the union would appeal the decision.
The union's lawyer argued last month that releasing the data would unfairly subject teachers to public ridicule.
The teacher ratings are based on how well students performed on standardized tests. Five media organizations filed Freedom of Information Law requests for them.
The media groups' lawyer, David Schulz, praised the ruling.