Import & export CSV data

Bulk-import catalogs, members, or legacy records via CSV and JSON without broken types, and export clean Live tables for accounting or backups.

When to use CSV vs JSON vs in-app importers

Migrating 300 products, loading a member roster, or sending monthly totals to an accountant goes far faster with structured bulk tools. ExaSpark supports direct table inspection in Cloud alongside custom admin import/export screens inside your app.

MethodBest suited forStrengthsWatch-outs
Cloud table editing & importLaunch seeding, one-time migrations, quick fixesDirect view of Preview vs Live rows; zero extra UI neededVerify column types and the Preview/Live switcher first
In-app Admin CSV importerWeekly staff uploads (inventory, classes, rosters)Dry-run preview, friendly row errors, role-gated accessEnforce admin auth and validation strictly on the server
JSON bulk importNested records, arrays, multi-table seedsExact types (number, boolean, null) without quoting quirksLess comfortable for non-technical staff in spreadsheets
Server CSV exportAccounting, CRM exports, compliance backupsOpens cleanly in Excel, Sheets, QuickBooks, and XeroMust enforce admin auth, escape formulas, and filter dates

Remember that Preview and Live never share rows. Test a 500-item catalog import in Preview first, then run the verified upload on Live. See Preview vs Live isolation.

Preparing clean CSV files before upload

Most failed CSV uploads stem from spreadsheet quirks in Excel or Numbers. Check five details before importing:

  • Save as UTF-8 CSV. Older Excel exports scramble accented names (José, Café). Choose CSV UTF-8 in Excel or export directly from Google Sheets.
  • Keep prices consistent. Supply integer minor units (2450) for price_cents, or instruct your importer to strip $ symbols and convert decimals to cents server-side.
  • Use ISO-8601 dates. Avoid ambiguous dates like 04/06/2026. Format calendar dates as 2026-06-04 and moments as 2026-06-04T14:30:00Z.
  • Keep booleans explicit. Use true and false consistently instead of mixing Yes, 1, and blank cells.
  • Quote commas and line breaks. Wrap text containing commas in double quotes ("Hand-thrown mug, 12oz").
csv
sku,title,category_slug,price_cents,stock_qty,is_active,published_at
MUG-001,"Stoneware Coffee Mug, 12oz",ceramics,2800,42,true,2026-05-01T00:00:00Z
MUG-002,"Matte Espresso Cup Set",ceramics,3600,18,true,2026-05-01T00:00:00Z
BEAN-010,"House Blend Whole Bean (340g)",coffee,1950,120,true,2026-05-01T00:00:00Z
TOTE-004,"Heavyweight Canvas Tote",merch,2200,0,false,2026-05-01T00:00:00Z

Using a readable unique key like category_slug (ceramics) instead of a raw UUID lets your importer resolve categories.id cleanly across both Preview and Live.

Handling foreign keys and duplicate rows

Importing across linked tables — such as categories and products, or instructors and classes — requires clear ordering and a deliberate conflict policy.

Import parent tables before child tables

Always load parent records first (categories before products). Reject any row referencing an unknown parent with an actionable error (Row 14: unknown category_slug "tea-ware") during dry-run validation.

Pick an explicit duplicate policy

Teams rarely upload a catalog only once. Match rows by a natural unique key (sku or lowercase email) and choose one rule:

  • Upsert (update existing, insert new). Ideal for inventory and price refreshes keyed by sku while keeping linked order history intact.
  • Skip existing. Ideal for lead lists or member rosters when you must preserve edits existing members already saved.
  • Reject on duplicate. Ideal for accounting ledgers or one-time redemption codes where repeats signal a spreadsheet error.

Never import raw passwords for legacy users

When migrating members from another platform, import profile columns (email, full_name, membership_tier) without plaintext passwords. Let returning members claim access via password reset, magic link, or Google/Apple login.

Step-by-step: importing into Preview, then Live

Treat every first-time bulk import like a dress rehearsal in Preview before touching Live customer records.

  1. Verify target table columns in Cloud

    Open Cloud → Preview, inspect the target table's column names, types, and required fields, and confirm any referenced parent rows exist.

  2. Dry-run a 10-row sample in Preview

    Import a small slice containing tricky edge cases (accented names, commas in descriptions, zero stock, empty optional fields) before uploading the entire file.

  3. Spot-check screens and totals in Preview

    Open your app's catalog, detail pages, filters, and admin dashboard to verify prices render as dollars (not cents multiplied by 100), dates align with your time zone, and foreign keys join properly.

  4. Switch to Live and run the full upload

    Once Preview looks spotless, run the full validated import against Live (or through your Live admin importer) and confirm the final row count in Cloud → Live.

Building an admin CSV import and export tool

If your team or clients will import inventory or download accounting reports regularly, ask ExaSpark to build a dedicated admin CSV screen right inside your app. Good production importers and exporters share four safeguards:

  • Strict admin authorization on the server. Every import and export route must verify session.user.role === 'admin' on the server — never leave an /api/export/orders.csv endpoint reachable by guests or regular members.
  • Two-step dry-run preview before writing. Parse the uploaded CSV on the server, validate every row's types and foreign keys, and display a summary ("142 ready to insert, 18 to update, 3 errors with row numbers") before the admin clicks Confirm import.
  • Accountant-friendly export columns. Export both machine-exact columns (total_cents, currency, created_at_utc) and human-readable columns (total_formatted, local_date) with date-range and status filters so bookkeepers do not fight formulas.
  • CSV formula injection protection. On export, prefix any user-entered cell starting with =, +, -, or @ with a leading apostrophe (or safe quoting) so opening a customer's name or address in Excel can never trigger malicious spreadsheet formulas.
Starter prompt · App

Build an admin-only CSV import and export panel under `/admin/data`. For product imports, accept UTF-8 CSV uploads up to 5 MB, run a server-side dry-run preview first showing rows to insert, rows to update by `sku`, and exact row-level validation errors (invalid integer `price_cents`, missing `category_slug`, blank `title`). Write changes in a single transaction only after admin confirmation. For order exports, let admins filter by UTC date range and payment status, stream a UTF-8 CSV with both `total_cents` and formatted dollar totals, escape spreadsheet formula prefixes (`=`, `+`, `-`, `@`), and enforce `role === 'admin'` on every endpoint.

Common CSV import & export errors

When a spreadsheet refuses to import cleanly or opens weirdly in Excel, match the symptom below to fix the root cause fast.

SymptomRoot causeClean fix
Accented names turn into `José`File was saved as Windows-1252 / Latin-1 instead of UTF-8, or Excel ignored UTF-8 on openSave uploads as UTF-8 CSV and emit a UTF-8 BOM header on CSV downloads for Excel compatibility
ZIP codes or SKUs lose leading zeros (`02138` becomes `2138`)Excel auto-parsed text identifiers as numeric columns when re-savedKeep identifier columns as text in your schema and format them as Plain Text before exporting from Sheets
Prices appear 100x too high or lowCSV supplied $24.50 into price_cents, or supplied cents where dollars were expectedStandardize your template header explicitly (price_cents vs price_dollars) and validate format on dry run
Every date shifted back by one dayLocal date strings were parsed as UTC midnight and displayed in a western time zoneStore calendar-only dates as YYYY-MM-DD and event moments as full ISO-8601 UTC timestamps
Re-uploading a sheet doubled every rowImporter ran blind inserts without matching a unique keyEnforce a UNIQUE index on sku or email and switch the importer to upsert by that key
Export times out on 20,000 rowsServer tried to serialize every table join in memory without filtersAdd required date-range filters, select only needed columns, and stream CSV rows from the server

Next steps

Still have a question?Ask our team and other builders on Discord.

From the blog