A federal judge ruled that a Massachusetts law against surreptitiously recording audio of police or government officials was unconstitutional on Monday in response to two cases that pressed the issue.

In both cases, defendants had not secretly recorded police but wished to do so. One of the lawsuits, filed by the ACLU on behalf of two people who "frequently record police officers," colloquially known as "copwatchers," said they wanted to be allowed to secretly record police because doing so openly could "endanger their safety and provoke hostility from officers."

Chief United States District Judge Patti B. Saris ruled that the claim was not without merit.

One of the activists, Eric Martin, has openly recorded police in public at least 26 times since 2011, while the other activist, Rene Perez, has done so 18 times.

The second lawsuit came from Project Veritas, an organization founded by James O'Keefe, the conservative media activist known for conducting undercover hit jobs on his political opponents.

Veritas argued that four different projects it wanted to do in the state were hindered by the law. Those projects would have included: an investigation into college students being rented unsafe rooms by landlords, a project on government official's stances on sanctuary cities, a piece on police management of antifascist protests and another on Harvard University's use of federal funds.

The defendants in both cases were Suffolk District Attorney Daniel Conley and Boston Police Commissioner William Gross, MassLive reported.

"Secret audio recording of government officials, including law enforcement officials, performing their duties in public is protected by the First Amendment, subject only to reasonable time, place and manner restrictions," Judge Saris said.

In the county, the DA's office has opened 11 felony cases for violations of the law, which bans secretly recording anyone. Some of those cases involved recording police officers. The Boston Police Department has also sought criminal complaints against nine people for secretly recording officers.

Boston Police training videos instruct officers that citizens recording them with notice is permissible, but that doing so privately is illegal. That video is reportedly mandatory viewing in the department.

Those videos reveal that the decision to enforce the law was a conscious choice by the department, as police officers are allowed discretion when they make arrests, the court ruled.