AskDB
·4 min read

How to Generate Test Data: CSV and JSON to SQL

Every developer needs test data at some point. Whether you are setting up a development environment, writing integration tests, or demoing a feature, generating realistic INSERT statements quickly saves hours of manual work.

Why Convert CSV or JSON to SQL?

Test data often comes in CSV or JSON format from product exports, API responses, or spreadsheets. Converting this data to SQL INSERT statements lets you populate databases directly without writing custom import scripts.

Method 1: CSV to SQL

If your data is in a spreadsheet, export it as CSV and use the CSV to SQL converter. The first row becomes column names, and each subsequent row becomes a VALUES tuple.

-- CSV input:
name,email,role
Alice,alice@example.com,admin
Bob,bob@example.com,user

-- Generated SQL:
INSERT INTO your_table (name, email, role)
VALUES
('Alice', 'alice@example.com', 'admin'),
('Bob', 'bob@example.com', 'user');

Method 2: JSON to SQL

When your data comes from an API or is structured as JSON objects, use the JSON to SQL converter. It handles arrays of objects and extracts keys as column names.

Tips for Better Test Data

  • Use realistic but fake data to avoid privacy issues
  • Include edge cases: empty strings, special characters, very long values
  • Add enough rows to test pagination and performance
  • Include NULL values to test nullable column handling
  • Match your actual schema column types

Automating Test Data Generation

For recurring needs, consider maintaining a CSV or JSON file in your repository as a seed data source. Run it through the converter whenever you need to reset your development database. This approach keeps test data version-controlled and easy to update.

Both converters run entirely in your browser, so your data never leaves your machine. Try them out with your own data to see how quickly you can populate a test database.