Array of Arrays to CSV Converter
Convert JavaScript array-of-arrays to CSV format online. RFC 4180 compliant with custom delimiters, quoting options, and instant download.
About
Converting a JavaScript array of arrays into RFC 4180-compliant CSV is deceptively error-prone. Naive implementations fail on fields containing the delimiter character, embedded newlines (\n), or double-quote characters (") that require escaping by doubling. A malformed CSV can corrupt an entire data pipeline or cause silent column misalignment in spreadsheet imports. This tool parses raw JavaScript array literal syntax safely - without eval() - and produces spec-compliant output with configurable delimiters and quoting strategies. It handles edge cases including null, undefined, boolean values, numeric literals (hex 0xFF, binary 0b1010, scientific 1.5e3), and nested arrays which are flattened into rows.
Limitation: this tool expects valid JavaScript array-of-arrays syntax. Objects, Maps, Sets, and function calls are not supported. Maximum practical input size is approximately 5 MB of source text in modern browsers. For arrays with inconsistent row lengths, shorter rows are padded with empty fields to match the longest row.
Formulas
The CSV encoding function processes each cell value v in row i, column j through the following quoting logic per RFC 4180:
Where escape(v) replaces every occurrence of " with "" (doubled double-quote). The full row output is:
Where delim = the chosen delimiter character, n = max(row lengths) − 1. Rows shorter than n + 1 columns are right-padded with empty strings. The safe parser tokenizes the input without eval(), recognizing array brackets [ ], string literals with escape sequences, numeric literals including 0x, 0o, 0b prefixes, and keywords true, false, null, undefined.
Reference Data
| Delimiter | Symbol | Common Use Case | RFC 4180 | Excel Compatible | Notes |
|---|---|---|---|---|---|
| Comma | , | Universal CSV | Yes | Yes (EN locales) | Default standard delimiter |
| Semicolon | ; | European CSV | No | Yes (EU locales) | Avoids conflict with decimal comma |
| Tab | \t | TSV files | No | Yes | Paste-friendly for spreadsheets |
| Pipe | | | Data pipelines | No | No | Rare in field values, reduces quoting |
| Quoting Strategies | |||||
| Auto | - | Minimal output | Yes | Yes | Quotes only when field contains delimiter, quote, or newline |
| Always | " | Safety-first | Yes | Yes | Every field wrapped in double quotes |
| Never | - | Simple data | No | Risky | No quoting; may break on special characters |
| Supported JS Literal Types | |||||
| String | "abc" | Text fields | - | - | Single, double, and backtick quotes supported |
| Number (int) | 42 | Numeric data | - | - | Decimal, hex (0x2A), octal (0o52), binary (0b101010) |
| Number (float) | 3.14 | Measurements | - | - | Scientific notation supported (1.5e3) |
| Boolean | true | Flags | - | - | Converted to string "true" / "false" |
| null | null | Missing values | - | - | Converted to empty string by default |
| undefined | undefined | Omitted values | - | - | Converted to empty string by default |
| RFC 4180 Escaping Rules | |||||
| Rule 1 | Fields containing line breaks (CRLF), double quotes, or the delimiter must be enclosed in double quotes | ||||
| Rule 2 | Double-quote characters inside a quoted field are escaped by preceding with another double quote ("") | ||||
| Rule 3 | Each record is on a separate line, delimited by a line break (CRLF) | ||||
| Rule 4 | The last record may or may not have an ending line break | ||||
| Rule 5 | An optional header line may appear as the first line with the same format as normal records | ||||