Business groups, worried about their revenue, have reacted angrily to the plans.
But President Ollanta Humala told them: "We cannot view our children as simply a market to generate sales and maximize profits."
One feature of the new law is a plan to set up stands selling quinoa, an ancient and healthy Andean grain, in schools.
Advertising will be regulated to ban those that encourage immoderate consumption of food and non-alcoholic beverages loaded with trans fats, sugar, salt and saturated fats, the law says.
The Peruvian Economics Institute derided the law as intrusive and heavy handed.
But the Peruvian Medical Association's president Juan Villena backed it: it was as important to regulate ads for junk food as it was ads for cigarettes, he argued.
Humala has said the law has international support and puts Peru on the cutting edge of healthy food legislation in the Andean region.