Developer Tools

Clean API Data Before Importing

· QuickToolFlow
api json csv data cleanup

API data often looks usable at first glance. It is structured, machine-readable, and easy to copy. But importing raw API responses directly into a spreadsheet, database, dashboard, or internal tool can create quiet problems: missing fields, nested values, inconsistent types, duplicate records, and timestamps nobody can read.

A short cleanup workflow prevents those problems before they spread into reports or production systems.

Step 1: Validate the Response

Start by confirming that the response is valid JSON. A copied response can include extra logs, comments, partial output, or a truncated object.

Paste the response into the JSON Formatter & Validator. If it does not parse, fix the syntax issue before doing anything else. Formatting invalid JSON is like labeling boxes before checking whether the boxes have bottoms.

Once it parses, format it so nested objects and arrays are easier to inspect.

Step 2: Identify the Actual Records

API responses often wrap the useful records inside metadata:

{
  "page": 1,
  "total": 240,
  "data": [
    { "id": 1, "name": "Ada" },
    { "id": 2, "name": "Grace" }
  ]
}

The import target probably wants the records inside data, not the entire response object. Use the JSON Path Tester to locate the array you need, such as $.data[*].

This step is especially useful when responses include items, results, edges, nodes, or nested pagination structures.

Step 3: Check Field Names and Types

Before importing, review the keys and values:

  • Are required fields always present?
  • Are numeric values numbers or strings?
  • Are booleans true booleans or text values like "yes" and "no"?
  • Are timestamps in seconds, milliseconds, or ISO date strings?
  • Are nested objects expected by the destination?

If another system depends on a strict contract, validate the sample with the JSON Schema Validator. Schema validation helps catch type drift before the data reaches a database or analytics pipeline.

This is also the point where you should decide whether the data is stable enough to automate. A one-time spreadsheet cleanup can tolerate a little manual review. A recurring import job needs stricter rules, clear defaults, and alerts when the API shape changes.

For API responses, compare the sample against the expected contract:

Field issueWhy it mattersTypical fix
Missing keyImport columns may shift or failAdd defaults or reject the row
String numberSorting and calculations may breakConvert to a number before import
Mixed date unitsReports can show wrong datesNormalize seconds, milliseconds, or ISO
Nested objectCSV columns may be unclearFlatten intentionally
Array valueOne cell may hide multiple recordsSplit into related rows when needed

Step 4: Flatten Nested Data Carefully

Spreadsheets and CSV files prefer rows and columns. JSON often contains nested objects and arrays. That means flattening may be necessary:

{
  "id": 1,
  "profile": {
    "country": "US",
    "plan": "pro"
  }
}

This might become columns such as id, profile.country, and profile.plan.

Arrays need more thought. A list of tags can be joined into one cell, but a list of orders may need a separate table. Do not flatten nested data blindly if relationships matter.

Step 5: Convert Only After Cleanup

Once the JSON is valid, the record array is clear, and the fields look stable, convert it to the target format.

Use the JSON to CSV Converter when the destination is a spreadsheet, reporting tool, or simple table import. After conversion, check the CSV headers, row count, blank cells, and quoted values.

If you are moving in the other direction, use the CSV to JSON Converter after cleaning headers and delimiters.

If the final format is YAML, XML, or another structured format, still start with validation. Conversion tools are most reliable when the source document is already valid and the record boundary is clear. For broader comparisons between structured formats, see JSON vs YAML vs XML.

Step 6: Normalize Dates and IDs

Timestamps and identifiers deserve a separate review. A 10-digit Unix timestamp usually represents seconds. A 13-digit timestamp usually represents milliseconds. Mixing them can shift dates by years.

Use the Timestamp Converter or Timestamp Batch Converter when logs or exports contain multiple date values.

For IDs, keep leading zeros if they are meaningful. Spreadsheet tools may turn 00123 into 123, which can break product codes, ZIP codes, and external IDs.

Import Checklist

Before importing API data, confirm:

  • The JSON parses successfully.
  • The record array has been identified.
  • Required fields are present.
  • Data types match the destination.
  • Nested objects and arrays have a clear flattening strategy.
  • Dates, IDs, and empty values have been reviewed.
  • The converted file opens correctly before final import.

Test With a Small Sample First

Before importing a full API export, convert and import a small representative sample. Include normal records, empty fields, long text, nested objects, arrays, unusual characters, and date values.

This smaller test helps you catch mapping problems before they affect hundreds or thousands of rows. It also gives you a chance to confirm how the destination handles missing values, duplicate IDs, type coercion, and leading zeros.

After the sample import succeeds, compare the record count and a few individual fields against the source response. Do not rely only on a successful import message.

Common Cleanup Mistakes

The most common mistake is converting too early. If a nested API response is converted to CSV before the real record array is selected, the result may contain one giant row, repeated metadata, or columns that do not match the import target.

Another mistake is trusting the first sample response. APIs often return optional fields only when a condition is met. Test with records that include blank values, long text, special characters, multiple currencies, timezone offsets, and nested arrays.

Finally, avoid silently changing values during cleanup. If 00123 is an account code, converting it to 123 is data loss. If "false" is text but the destination expects a boolean, decide whether to convert it or reject the row. Cleaning data is not just making it look tidy; it is preserving meaning.

Keep going

Related tools and guides

All tools