How We Built a Nutrition Comparison Tool with 195 Foods

The nutrition data you see on this site comes from USDA FoodData Central โ€” the same database that powers food labels and research papers. Here's how we turned raw USDA API data into fast, accurate comparison pages for 195 common foods.

Why USDA FoodData Central?

There are several nutrition databases available, but USDA FoodData Central (FDC) is the gold standard for a few reasons:

  • It's the most comprehensive. The SR Legacy dataset contains over 8,000 foods with full nutrient profiles across 150+ nutrients.
  • It's authoritative. The data underlies FDA food labeling regulations. When a nutrition label says "15g protein," it's referencing USDA measurements.
  • It's free and has a public API. The FDC API gives programmatic access to the entire dataset at no cost.
  • It's standardized. All measurements are per 100g, making comparisons directly meaningful without serving-size confusion.

Step 1: Selecting 195 Foods

FDC has over 8,000 entries, but many are duplicates (different brands of the same food), highly processed products, or uncommon ingredients. We curated a list of 195 whole and minimally processed foods that represent what people actually eat and search for.

The selection criteria:

  • Whole or minimally processed (not branded packaged foods)
  • Commonly consumed in the US โ€” prioritized by search volume for nutrition queries
  • One entry per food (e.g., one "chicken breast" rather than dozens of brand variations)
  • Use SR Legacy data where available for maximum nutrient coverage

Step 2: Pulling and Cleaning the Data

We fetched nutrient profiles for each of the 195 foods via the FDC API. A few data quality issues required cleanup:

  • Missing values: Not every food has every nutrient measured. We treat missing values as zero in displays but flag them where nutritionally significant (e.g., B12 in plant foods is legitimately zero, not missing).
  • Unit normalization: FDC returns nutrients in various units (mg, mcg, IU). We converted everything to a standard unit for display consistency.
  • Preparation state: We default to raw/uncooked weights where available, since cooking changes measurements. A cooked lentil entry and a raw lentil entry have very different numbers โ€” we document which state we're showing.

Step 3: Building the Comparison Engine

The comparison tool is a client-side UI that lets you select any two foods and see their nutrients side-by-side. The logic is simple:

  1. Both food profiles are loaded from static JSON at page load.
  2. When a user selects two foods, we diff their nutrient values.
  3. We highlight the "winner" per nutrient (higher or lower, depending on context โ€” higher protein is good, higher saturated fat is flagged).
  4. We compute a summary score for key categories: protein, fiber, vitamins, minerals.

The entire comparison runs in the browser โ€” no API calls after the initial page load. This makes it fast and works offline.

Step 4: Generating Individual Food Pages

Each of the 195 foods has its own page (e.g., chicken breast, salmon, broccoli) showing the full nutrient profile and contextual comparisons. These are statically generated at build time from the JSON data snapshots.

We also pre-generate popular comparison pages (like chicken breast vs salmon) to ensure fast loading for the most-searched food pairs.

What We Learned About Nutrition Data

Building this tool surfaced some genuinely surprising things about how nutrition data works:

  • Nutrient density varies wildly even within a food category. The vitamin C content in different vegetables, for example, spans two orders of magnitude. Bell peppers have more vitamin C than oranges. The data doesn't lie.
  • Fiber data has more gaps than protein data. USDA measures fiber less consistently than macronutrients. Some fiber values we found were clearly estimated, not directly measured.
  • Cholesterol data is politically complicated. The 2015 Dietary Guidelines removed cholesterol limits, but the data is still there. We show it without a "bad" label, consistent with current science.

Accuracy and Limitations

A few important caveats about the data:

  • Nutrient content in real foods varies based on soil quality, growing conditions, breed (for animal foods), and ripeness. USDA values represent averages from tested samples.
  • Bioavailability โ€” how much your body actually absorbs โ€” differs across foods and isn't captured in raw nutrient data. Iron from lentils and iron from beef are both measured, but your body absorbs them at different rates.
  • We show uncooked weights by default. A 100g raw chicken breast becomes about 70g cooked. The calorie and protein counts stay roughly proportional, but micronutrients can shift with heat exposure.

With those caveats in mind, browse the full 195-food database or head to the comparison tool.

Stay Updated

Get weekly data insights delivered to your inbox.