UnifyUnits Developers

Normalize

POST /v1/normalize reads quantities as they appear in real catalogs, supplier files, and user input and returns one structure: what kind of quantity it is, the values as written, and the total in the category base unit. It is deterministic and never guesses: an unknown or ambiguous unit returns an error instead.

Supported forms

InputkindResult
12.5 kgsingle12.5 kg
2x500ml, 6 x 330 ml, pack of 6 x 330ml, 6-pack of 330 ml, 500ml x 2multipackcount, each, and total
1 lb 4 oz, 5 ft 11 in, 5'11"mixedtotal in the smallest unit used (20 oz, 71 in)
10-12 cm, 10 to 12 cm, 10 cm - 12 cmrangemin and max
approx 5kg, ~5 kg, about 5 kg, circa 5kganyqualifier: "approximate"

Every response has the same fields. Fields that do not apply to the kind are null: count and each for multipacks, total and base for everything except ranges, and min, max, base_min, and base_max for ranges. base values use the base_unit of the category.

Example

bash
curl "https://api.unifyunits.com/v1/normalize" \
  -X POST \
  -H "Authorization: Bearer $UNIFYUNITS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"text":"1 lb 4 oz","decimals":3}'
json
{
  "data": {
    "kind": "mixed",
    "qualifier": null,
    "category": "mass",
    "base_unit": "kg",
    "count": null,
    "each": null,
    "total": { "value": "20", "unit": "oz" },
    "min": null,
    "max": null,
    "base": { "value": "0.567", "unit": "kg" },
    "base_min": null,
    "base_max": null
  }
}

Decimal separators and locale

1,5 is read as 1.5 and 1,234.56 or 1.234,56 as 1234.56, because the last separator is the decimal one. Exactly three digits after a single separator is ambiguous, so the locale decides:

InputNo locale or ende, fr, es, and similar
1,500 g15001.5
1.500 g1.51500

Pass a language tag such as "de-DE". Spaces are not treated as thousands separators, except non-breaking spaces; malformed numbers such as 1.2.3 are rejected.

Rules and limits

  • NxM unit always means N packs of M unit. A dimension such as 2x4 ft is read as two pieces of 4 ft.
  • Mixed values need units of the same category with a fixed factor, each used once. Temperatures cannot be mixed.
  • Range ends must be the same kind of unit and the minimum cannot exceed the maximum.
  • Counts are whole numbers from 1 to 100,000.
  • A successful call uses one conversion from your monthly quota. Failed calls are free.