DataScrub

Custom Script

Write JavaScript to transform your data row by row. The power-user escape hatch — if our other tools don't cover it, code it yourself.

Drag & drop your file here

or click to browse

CSVTSVExcelODSJSON

Transform Data with Custom JavaScript

Sometimes no pre-built tool covers your exact need. You want to parse a price like "$1,234.56" into a number, calculate a new column from existing ones, apply conditional logic, or reformat values with custom rules. DataScrub's Custom Script lets you write JavaScript that runs on every row — instant preview, no setup needed.

How to Write a Custom Script

  1. Upload your CSV, Excel, or ODS file.
  2. Write JavaScript in the code editor.
  3. Your code runs per row with access to row, index, and total variables.
  4. Preview the first 5 rows live to verify your logic.
  5. Apply the script to all rows.
  6. Download the transformed file.

Available Variables

Your script receives three variables for each row it processes. Modify the row object in place to transform your data.

  • row — the current row as a JavaScript object you can read and modify. All values are strings by default.
  • index — the 0-based row number, useful for adding sequential IDs or conditional logic based on position.
  • total — the total number of rows, useful for progress calculations or percentage-based transformations.

Common Script Examples

Here are practical snippets you can adapt for your own data. Each one modifies the row object directly.

  • Parse prices: row.price = parseFloat(row.price.replace('$', ''))
  • Calculate totals: row.total = (parseFloat(row.price) * parseFloat(row.qty)).toFixed(2)
  • Extract domains: row.domain = row.email.split('@')[1]
  • Conditional tags: row.tier = parseFloat(row.revenue) > 1000 ? 'premium' : 'standard'

Tips for Writing Scripts

  • Start with a template snippet from the built-in library — you can modify it from there.
  • Use parseFloat() for number conversions, since all CSV values are read as strings.
  • Test on the live preview before applying to all rows — the first 5 rows update instantly.
  • Errors in one row won't stop others from processing. Problematic rows keep their original values.

Frequently Asked Questions

Do I need to know JavaScript?

Basic JavaScript knowledge helps, but the built-in template snippets cover the most common transformations. You can start from a template and modify the column names and values to match your data without writing code from scratch.

What happens if my script has an error?

Syntax errors are caught before any rows are processed and displayed in a red error panel. Runtime errors in individual rows are handled gracefully — the failing row keeps its original values and the error is logged, while all other rows continue processing normally.

Can I add new columns?

Yes. Simply assign a new property to the row object, such as row.full_name = row.first_name + ' ' + row.last_name. New columns appear in the output alongside the original ones.

Is there a limit on script complexity?

There is no hard limit on how complex your script can be, but keep in mind that it runs once per row in your browser. Very large datasets combined with heavy computation may cause slowdowns. For best performance, keep your logic straightforward and avoid nested loops inside the script.