Attorney General Kamala Harris' office filed the lawsuit in San Francisco Superior Court.
The suit claims retailers and candy makers exposed consumers to lead in violation of Proposition 65, which requires businesses to issue warnings about even minute amounts of chemicals deemed harmful by the state.
The attorney general's office says laboratory tests verified the lead in the products.
"Defendants ... have knowingly and intentionally exposed individuals within the state of California to lead," the complaint states.
The suit names other big retailers like Target, and dozens of other smaller companies and candy makers.
Under Proposition 65, a product that contains even small amounts of lead or other chemicals identified by the state as harmful to human health must carry a label warning consumers.
If found to be at fault by a judge, the candy makers and retailers could be fined up to $2,500 per day for each violation.
Lead exposure can damage the developing brains of children and lead to lower IQ.
While overall cases of lead poisoning have dropped in recent years, more than 500,000 U.S. children are still believed to have lead poisoning, according to the Centers for Disease Control and Prevention.
The primary sources for lead exposure to children in the U.S. are old paint, contaminated drinking water and soil tainted by old leaded gasoline, the CDC reported.
At Whole Foods, the suit named the market's "bulk ginger" and The Ginger People Baker's Cut Crystallized Ginger Chips as not complying with the law. At Trader Joe's, the suit names un-crystallized candied ginger.
Whole Foods Market California Inc. and Trader Joe's Co. did not immediately return calls for comment.