Field name matching, also called column matching or schema mapping, decides which column in an uploaded file belongs to which field in your system. It turns headers such as E-mail Addr, SURNAME, and Ph# into email, last_name, and phone so the data lands in the right place. Common algorithms include edit distance (Levenshtein and Damerau-Levenshtein), Jaro-Winkler similarity, token overlap, and phonetic codes such as Soundex.
Why it matters when importing data
No two customers name their columns the same way, and a wrong match is worse than no match: phone numbers end up in the fax field and nobody notices until a report looks odd. Good matching gets most headers right automatically, leaves the uncertain ones for a person to confirm, and never silently guesses.
Field Name Matching in JavaScript
A practical matcher works in layers. Normalize the header, check it against known aliases, then fall back to a similarity score with a threshold. This one uses edit distance, which counts a swapped pair of letters as one edit, so typos such as Emial still match:
// The fields your application expects, with known aliases for each.
const schema = {
first_name: ["first name", "firstname", "given name", "fname"],
last_name: ["last name", "lastname", "surname", "family name"],
email: ["email", "e-mail", "email address", "e-mail addr"],
phone: ["phone", "phone number", "tel", "mobile", "ph#"],
postal_code: ["zip", "zip code", "postal code", "postcode"],
};
const normalize = (header) =>
header
.toLowerCase()
.replace(/[^a-z0-9#]+/g, " ")
.trim();
// Edit distance that counts a swap of two adjacent letters as one edit.
function editDistance(a, b) {
const d = Array.from({ length: a.length + 1 }, (_, i) => [
i,
...Array(b.length).fill(0),
]);
for (let j = 1; j <= b.length; j++) d[0][j] = j;
for (let i = 1; i <= a.length; i++) {
for (let j = 1; j <= b.length; j++) {
const cost = a[i - 1] === b[j - 1] ? 0 : 1;
d[i][j] = Math.min(
d[i - 1][j] + 1,
d[i][j - 1] + 1,
d[i - 1][j - 1] + cost
);
if (i > 1 && j > 1 && a[i - 1] === b[j - 2] && a[i - 2] === b[j - 1]) {
d[i][j] = Math.min(d[i][j], d[i - 2][j - 2] + 1);
}
}
}
return d[a.length][b.length];
}
function score(header, alias) {
if (header === alias) return 1;
if (header.split(" ").includes(alias)) return 0.9; // "zip postal" contains "zip"
return (
1 - editDistance(header, alias) / Math.max(header.length, alias.length)
);
}
function matchHeader(rawHeader, threshold = 0.75) {
const header = normalize(rawHeader);
let best = { field: null, score: 0 };
for (const [field, aliases] of Object.entries(schema)) {
for (const alias of [field.replace(/_/g, " "), ...aliases].map(normalize)) {
const s = score(header, alias);
if (s > best.score) best = { field, score: s };
}
}
return best.score >= threshold ? best : { field: null, score: best.score };
}
const headers = [
"First Name",
"SURNAME",
"E-mail Addr",
"Ph#",
"Zip/Postal",
"Emial",
"Notes",
];
const results = headers.map((header) => {
const { field, score: s } = matchHeader(header);
return { header, field, score: Number(s.toFixed(2)) };
});
console.table(results); Output
| Header in file | Matched field | Score |
|---|---|---|
| First Name | first_name | 1 |
| SURNAME | last_name | 1 |
| E-mail Addr | 1 | |
| Ph# | phone | 1 |
| Zip/Postal | postal_code | 0.9 |
| Emial | 0.8 | |
| Notes | null | 0.4 |
Edge cases to handle
- Thresholds. Too low and
Notesmatchesphone. Too high and typos go unmatched. Below the threshold, ask a person. - One column, one field. Two headers can both score well against
email. Assign each field once and keep the best match. - Meaning, not spelling.
Cellis a phone number but looks nothing likephone. An alias list, such as themobilealias above, or a semantic model catches these; edit distance does not. - Remember confirmed matches. The same customer will upload the same layout again. Save their confirmed mapping and reuse it.
How Dromo handles field name matching
Dromo matches headers against each field's label, key, and alternateMatches, uses fuzzy matching for near misses, and uses AI to catch matches a string comparison would miss, such as Cell for phone. With autoMapHeaders turned on, which requires backendSyncMode set to MAPPINGS_ONLY or FULL_DATA, Dromo reuses the mapping from previous uploads with the same importIdentifier, and requireMapping stops the user from continuing until a critical field is matched.
Related terms
- Dynamic Data Validation: Validating data against rules or reference data that are loaded at runtime.
- Normalizing Cases: Converting text to a consistent case so equal values compare as equal.
- Trimming Fields: Removing unwanted whitespace from the start and end of a value.
Frequently asked questions
What is a name matching algorithm?
A name matching algorithm scores how similar two names are, for example by comparing them after normalization, by counting the edits needed to turn one into the other, or with a model trained on known matches, and treats scores above a threshold as a match.
Can machine learning do field matching?
Yes. Models can match headers by meaning rather than spelling, such as Cell to phone, and learn from mappings users have confirmed. They work best combined with exact alias rules and a person confirming low-confidence matches.