DEV Community

Dani
Dani

Posted on

Parsing "2-3 cloves garlic, minced" is harder than it looks

{
  "original": "2 1/2 cups chopped yellow onion",
  "quantity": 2.5,
  "quantity_max": null,
  "unit": "cup",
  "unit_type": "volume",
  "size": null,
  "ingredient": "yellow onion",
  "prep": "chopped",
  "notes": [],
  "metric": {"quantity": 591.5, "unit": "ml"}
}
Enter fullscreen mode Exit fullscreen mode

And the tricky ones come out clean too:

Line quantity unit ingredient extra
1 (14.5 oz) can diced tomatoes 1 can tomatoes size: 14.5 oz, prep: diced
2-3 cloves garlic, minced 2 (max 3) clove garlic prep: minced
Salt to taste null null Salt notes: to taste

It handles fractions (1/2, ½, 1½), ranges (2-3, 2 to 3),
US and metric units, size words like large, and notes like optional
or for garnish.

Quick example (Python)

import requests

resp = requests.post(
    "https://ingredient-parser5.p.rapidapi.com/parse-batch",
    json={"ingredients": [
        "2 1/2 cups chopped yellow onion",
        "2-3 cloves garlic, minced",
    ]},
    headers={
        "X-RapidAPI-Key": "your-key",
        "X-RapidAPI-Host": "ingredient-parser5.p.rapidapi.com",
    },
)
for item in resp.json()["results"]:
    print(item["quantity"], item["unit"], item["ingredient"])
Enter fullscreen mode Exit fullscreen mode

Use /parse for one line or /parse-batch for up to 100 at once.

What people use this for

  • Shopping lists that combine "1 cup onion" and "1/2 cup onion" into one line
  • Nutrition lookups, where you need the ingredient name separated from the amount
  • Pantry and meal-planning apps

Try it

There's a free plan, so you can throw your messiest ingredient lines at
it without paying anything.

👉 Ingredient Parser on RapidAPI

Need the ingredient lines in the first place? My
Recipe Extractor
pulls them from any recipe link.

Found a line it gets wrong? Drop it in the comments. Those are the most
useful bug reports I get.

Top comments (0)