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
| Input | kind | Result |
|---|---|---|
12.5 kg | single | 12.5 kg |
2x500ml, 6 x 330 ml, pack of 6 x 330ml, 6-pack of 330 ml, 500ml x 2 | multipack | count, each, and total |
1 lb 4 oz, 5 ft 11 in, 5'11" | mixed | total in the smallest unit used (20 oz, 71 in) |
10-12 cm, 10 to 12 cm, 10 cm - 12 cm | range | min and max |
approx 5kg, ~5 kg, about 5 kg, circa 5kg | any | qualifier: "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
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}'
{
"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:
| Input | No locale or en | de, fr, es, and similar |
|---|---|---|
1,500 g | 1500 | 1.5 |
1.500 g | 1.5 | 1500 |
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 unitalways means N packs of M unit. A dimension such as2x4 ftis 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.