Skip to main content
SplitBox formats each batch according to your output preferences. Choose from four templates and three delimiters to match your downstream requirements.

Output templates

Templates control how items are formatted and wrapped in each batch.
type OutputTemplate = 'plain' | 'sql_in' | 'quoted_csv' | 'json_array';

Plain text

Simple delimiter-separated output with no special formatting. Items are joined exactly as provided. Example output:
TXN-001
TXN-002
TXN-003
Use cases:
  • Basic text processing
  • Import into spreadsheets
  • Unix command pipelines

SQL IN clause

Formats items as a SQL-safe IN clause with proper escaping and parentheses. Template: ('item1', 'item2', 'item3') Example output:
('TXN-001', 'TXN-002', 'TXN-003')
Use in queries:
SELECT * FROM transactions
WHERE transaction_id IN ('TXN-001', 'TXN-002', 'TXN-003');
SQL injection protection:
function escapeSqlValue(value: string): string {
  return `'${value.replaceAll("'", "''")}' `;
}
Single quotes in values are automatically escaped using SQL standard escaping (' becomes '').
Example with escaping:
O'Brien
Smith's Account
Normal-ID

Quoted CSV

Formats items as a quoted CSV row with proper escaping for commas and quotes. Example output:
"TXN-001","TXN-002","TXN-003"
CSV escaping:
function escapeCsvValue(value: string): string {
  return `"${value.replaceAll('"', '""')}`;
}
Double quotes in values are escaped by doubling them (" becomes "") per RFC 4180.
Example with escaping:
Product "A"
Item, Special
Normal-ID
Use cases:
  • Import into Excel/Google Sheets
  • CSV file generation
  • Data interchange

JSON array

Formats items as a pretty-printed JSON array. Example output:
[
  "TXN-001",
  "TXN-002",
  "TXN-003"
]
Implementation:
JSON.stringify(items, null, 2)
JSON output uses 2-space indentation for readability. Special characters are automatically escaped by JSON.stringify().
Use cases:
  • API request bodies
  • JavaScript/TypeScript code
  • Configuration files

Output delimiters

Delimiters only apply to the plain text template. Other templates have fixed formatting.
type OutputDelimiter = 'newline' | 'comma' | 'tab';

Newline

One item per line. Best for readability and Unix tools.
item1
item2
item3

Comma

All items on one line, comma-separated.
item1,item2,item3

Tab

All items on one line, tab-separated (TSV format).
item1	item2	item3

File extensions

When you download a batch, the file extension matches the template:
function getTemplateFileExtension(outputTemplate: OutputTemplate): 'txt' | 'sql' | 'csv' | 'json' {
  if (outputTemplate === 'sql_in') return 'sql';
  if (outputTemplate === 'quoted_csv') return 'csv';
  if (outputTemplate === 'json_array') return 'json';
  return 'txt';
}
TemplateExtensionExample filename
Plain.txtsplitbox-batch-1.txt
SQL IN.sqlsplitbox-batch-1.sql
Quoted CSV.csvsplitbox-batch-1.csv
JSON Array.jsonsplitbox-batch-1.json

Template selection guide

Plain text

When to use:
  • General-purpose text output
  • No special characters to escape
  • Simple list processing
Delimiter: Choose based on downstream tool (newline for Unix, comma for basic CSV, tab for TSV)

SQL IN

When to use:
  • Building SQL queries
  • Items may contain single quotes
  • Need proper SQL escaping
Perfect for: WHERE id IN (...) clauses

Quoted CSV

When to use:
  • Spreadsheet import
  • Items contain commas or quotes
  • RFC 4180 compliance required
Perfect for: Excel, Google Sheets, data interchange

JSON Array

When to use:
  • API requests
  • JavaScript/TypeScript code
  • Structured data exchange
Perfect for: REST API bodies, config files

Implementation

The core formatting logic:
export function formatBatchContent(
  items: string[],
  outputTemplate: OutputTemplate,
  outputDelimiter: OutputDelimiter,
): string {
  if (outputTemplate === 'sql_in') {
    return `(${items.map(escapeSqlValue).join(', ')})`;
  }

  if (outputTemplate === 'quoted_csv') {
    return items.map(escapeCsvValue).join(',');
  }

  if (outputTemplate === 'json_array') {
    return JSON.stringify(items, null, 2);
  }

  return items.join(getJoinSeparator(outputDelimiter));
}

Common workflows

1

Database batch queries

Template: SQL INExample:
-- Batch 1
DELETE FROM orders WHERE id IN ('A001', 'A002', 'A003');

-- Batch 2
DELETE FROM orders WHERE id IN ('A004', 'A005', 'A006');
2

API batch requests

Template: JSON ArrayExample:
{
  "user_ids": [
    "user_123",
    "user_456",
    "user_789"
  ]
}
3

Spreadsheet import

Template: Quoted CSVExample: Download each batch as .csv and import directly into Excel
4

Unix pipeline processing

Template: Plain text (newline delimiter)Example:
# Process each item through a command
cat batch-1.txt | xargs -I {} process_item {}
You can switch output formats after splitting without re-running the split. SplitBox reformats all batches instantly when you change the template or delimiter.

Build docs developers (and LLMs) love