User Rating 0.0
Total Usage 0 times
0 chars
Paste a valid JS array literal. No eval() used — safe parsing only.
Is this tool helpful?

Your feedback helps us improve.

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.

array to csv javascript array converter csv generator array of arrays json to csv data conversion code utility

Formulas

The CSV encoding function processes each cell value v in row i, column j through the following quoting logic per RFC 4180:

{
quote(v) = " + escape(v) + ", if v contains delim " \nquote(v) = " + escape(v) + ", if quoting = ALWAYSquote(v) = v, otherwise

Where escape(v) replaces every occurrence of " with "" (doubled double-quote). The full row output is:

rowi = quote(vi,0) + delim + quote(vi,1) + ... + delim + quote(vi,n)

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

DelimiterSymbolCommon Use CaseRFC 4180Excel CompatibleNotes
Comma,Universal CSVYesYes (EN locales)Default standard delimiter
Semicolon;European CSVNoYes (EU locales)Avoids conflict with decimal comma
Tab\tTSV filesNoYesPaste-friendly for spreadsheets
Pipe|Data pipelinesNoNoRare in field values, reduces quoting
Quoting Strategies
Auto - Minimal outputYesYesQuotes only when field contains delimiter, quote, or newline
Always"Safety-firstYesYesEvery field wrapped in double quotes
Never - Simple dataNoRiskyNo quoting; may break on special characters
Supported JS Literal Types
String"abc"Text fields - - Single, double, and backtick quotes supported
Number (int)42Numeric data - - Decimal, hex (0x2A), octal (0o52), binary (0b101010)
Number (float)3.14Measurements - - Scientific notation supported (1.5e3)
BooleantrueFlags - - Converted to string "true" / "false"
nullnullMissing values - - Converted to empty string by default
undefinedundefinedOmitted values - - Converted to empty string by default
RFC 4180 Escaping Rules
Rule 1Fields containing line breaks (CRLF), double quotes, or the delimiter must be enclosed in double quotes
Rule 2Double-quote characters inside a quoted field are escaped by preceding with another double quote ("")
Rule 3Each record is on a separate line, delimited by a line break (CRLF)
Rule 4The last record may or may not have an ending line break
Rule 5An optional header line may appear as the first line with the same format as normal records

Frequently Asked Questions

The tool implements a custom recursive-descent tokenizer that reads the input character by character. It recognizes JavaScript array brackets, string literals (with proper escape sequence handling for \n, \t, \", \', \\, and Unicode escapes), numeric literals (decimal, hexadecimal 0x, octal 0o, binary 0b, and scientific notation like 1.5e3), boolean keywords (true/false), null, and undefined. This approach eliminates the security risk of arbitrary code execution that eval() introduces, while still supporting the full range of JavaScript literal syntax.
The converter finds the maximum row length across all rows and right-pads shorter rows with empty string values. This ensures every row in the CSV output has the same number of delimiter-separated fields, preventing column misalignment when imported into spreadsheets or databases. For example, [[1,2,3],[4,5]] becomes three columns where the second row's third field is empty.
Per RFC 4180, any field containing the delimiter character, a double-quote character, or a newline (CR, LF, or CRLF) is wrapped in double quotes. Double-quote characters within the field are escaped by doubling them. For example, the string He said "hello" becomes "He said ""hello""" in the CSV output. When using the "Never" quoting strategy, this escaping is skipped, which can produce malformed CSV if your data contains special characters.
European versions of Excel and LibreOffice Calc typically use the semicolon (;) as the CSV delimiter because the comma is used as the decimal separator in many European number formats. If you select the semicolon delimiter, the tool produces output compatible with these locales. Alternatively, Tab-separated values (TSV) are universally recognized regardless of locale settings.
The tool expects a two-dimensional structure: an outer array containing row arrays. If a cell value is itself an array (three levels deep), it is serialized to its JSON string representation and placed as a single cell value in the CSV. For example, [[1, [2,3]]] produces a row where the second cell contains the literal text [2,3]. This preserves data without loss but requires post-processing if you need to unpack those nested structures.
The practical limit depends on the browser's JavaScript engine memory. Modern browsers (Chrome, Firefox, Edge) can typically handle input text up to approximately 5 MB, corresponding to roughly 50,000-100,000 rows of moderate column width. For inputs exceeding this, the browser tab may become unresponsive. The tool provides a character count indicator to help you gauge input size.
The parser recognizes standard JavaScript escape sequences within string literals: \n (newline), \t (tab), \r (carriage return), \\ (backslash), \" (double quote), \' (single quote), \0 (null character), and Unicode escapes (\uXXXX and \u{XXXXX}). These are converted to their actual character values before CSV encoding. For instance, a string containing \n will produce a literal newline in the CSV cell, which will then be properly quoted per RFC 4180.