ForHosting KIT · Data & Files

Merge two CSV files on a key

Merge two CSV files on a key when one table supplies the primary records and another adds related fields.

● BetaFree · in your browser
Use it from WebAPIEmailTelegramApp soon

Paste both CSV texts, name the header they share, and receive a predictable left-joined result without setting up a database or writing a temporary script. The response also separates records that failed to match on the left and on the right, making omissions easy to review. Quoted values, repeated keys, header collisions, and common line endings are handled deterministically, so the same input always produces the same structured output.

Prepare two CSV files with a reliable shared key

Start by identifying the column that represents the same thing in both files, such as customer_id, order_number, sku, or email. The header spelling must match the key value you submit exactly, including capitalization and spaces. Every other header may differ. The left CSV is the primary table: every one of its records remains in the joined output, whether a matching right record exists or not. The right CSV contributes additional columns when its key value matches. Use a stable identifier whenever possible. Names and descriptions often change, contain inconsistent spacing, or repeat, while a system identifier is usually safer. The parser understands quoted fields, escaped double quotes, commas inside quoted values, embedded line breaks, CRLF files, and an initial UTF-8 byte-order mark. If both files use a separator other than a comma, provide that one-character delimiter. Both inputs must use the same delimiter. Empty and duplicate column names are rejected because they would make the resulting objects ambiguous. The capability also stops with a clear input error if the requested key header is absent from either CSV, rather than silently returning a misleading table with no matches.

Understand the left join and duplicate-key behavior

For each record in the left CSV, the capability looks up records in the right CSV with exactly the same key text. A single match produces one combined record. No match still produces one joined record: the original left fields are preserved and every contributed right field is an empty string. When the right file contains several records with the same key, the left record expands into one output record for each right-side match. This one-to-many behavior is useful for joining a customer to several subscriptions or a product to several warehouse entries, but it can increase the output row count. Duplicate keys on the left are processed independently and retain their original order. Rows and matches remain in source order, which keeps results deterministic and makes comparisons straightforward. The shared key appears only once in each joined object. If a non-key right header already exists on the left, its output name gains a right_ prefix so neither value is overwritten. Additional prefixes are added if necessary to keep every output header unique. The columns array gives the exact final order and names before you consume joined_rows in another system.

Use unmatched reports to reconcile data safely

A successful join is only part of a reconciliation task. The unmatched_left array contains original left records whose key had no counterpart on the right. These entries still appear in joined_rows because this is a left join, but the separate list lets you route them for correction, enrichment, or review. The unmatched_right array contains original right records that were never used by any left record. They do not appear in the joined table, yet they often reveal stale reference data, unexpected new identifiers, or a file supplied for the wrong reporting period. Counts summarize both source sizes, the expanded joined size, and unmatched totals, making automated quality checks simple. For example, a workflow can reject an import whenever unmatched_left is greater than zero or alert an operator when unmatched_right rises above an expected threshold. Matching is exact and does not trim, normalize case, or reinterpret numbers, so values such as 001, 1, and 1 with a trailing space remain distinct. That conservative rule prevents accidental associations. Normalize keys before calling this capability when your business rules explicitly allow those values to be treated as equivalent. At $0.002 per request through the API, the operation can be inserted into repeatable imports as well as used for one-off investigations.

Enrich customer exports

Add plan, territory, or account-owner fields from a reference CSV while retaining every customer in the primary export.

Reconcile orders and payments

Join transactions by order number and inspect unpaid orders and payments that reference an unknown order.

Audit product catalog coverage

Combine a master SKU list with supplier data, then find products missing supplier details and unused supplier rows.

What happens when the key column is missing?

The request fails with an invalid input error that identifies whether the key is missing from the left or right CSV.

Does the operation keep every left row?

Yes. It is always a left join. A left row without a match is returned with empty strings for contributed right-side fields.

How are duplicate key values handled?

Each left record is combined with every matching right record, producing multiple joined rows when the right key repeats.

What if both files contain a column with the same name?

The left column keeps its name. A conflicting non-key right column receives a right_ prefix, with further prefixes if required for uniqueness.

Are key values cleaned before matching?

No. Matching is exact and preserves spaces, capitalization, and leading zeros. Normalize values before submission if your rules require it.

Everything on this page is available programmatically. This section is for teams who want to wire it into their own systems; everyone else can just use the tool above.

POSThttps://api.kit.forhosting.com/data/merge-csv-on-key

Prefer to automate it? One authenticated POST creates the task; the result comes back by webhook or a signed link. The same capability also runs here on the web, by email and from Telegram — and soon from our app too.

curl -X POST https://api.kit.forhosting.com/data/merge-csv-on-key \
  -H "Authorization: Bearer $KIT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"left_csv":"id,name\n1,Ada\n2,Linus\n3,Grace","right_csv":"id,team\n1,Research\n2,Platform\n4,Support","key":"id"}'
{
  "left_csv": "id,name\n1,Ada\n2,Linus\n3,Grace",
  "right_csv": "id,team\n1,Research\n2,Platform\n4,Support",
  "key": "id"
}
{
  "task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
  "type": "data.merge_csv_on_key",
  "status": "queued",
  "_links": {
    "result": "/tasks/tsk_…/result"
  }
}

The API is asynchronous: the call returns a task_id immediately and the result arrives by webhook. Polling is capped at 1 req/s per task.

Per request$0.002

Published price — no tokens, no invented credits. A failed task is never charged.

max_mb25
HTTPCodeMeaning
401unauthorizedMissing or invalid API key.
402insufficient_balanceYour balance doesn't cover the task price.
404unknown_typeThat task type doesn't exist.
429rate_limitedToo many requests. Use the webhook instead of polling.

Read the full KIT documentation →