Nekonote Toolbox logo

Nekonote Toolbox

Free browser-based tools for developers and IT admins.

日本語

CSV/TSV to Array Code

Format

Array code


                        

Click the output to copy it to your clipboard.

About this tool

Copy a range of cells from Excel or Google Sheets (which pastes as tab-separated text), or paste a CSV, and get a ready-to-use array definition. It is useful for turning lookup tables, dropdown options, configuration lists and test data that live in a spreadsheet into code.

Everything runs in your browser. Your data is never sent to a server.

Example

Input (CSV, "Use the first row as keys" checked):
id,name
1,apple
2,orange

PHP output:
array(
  array('id' => '1', 'name' => 'apple'),
  array('id' => '2', 'name' => 'orange')
)

JSON output:
[
  { "id": "1", "name": "apple" },
  { "id": "2", "name": "orange" }
]

How it works

  • Without the header option, the result is a two-dimensional array (a list of rows). With it, each row after the first becomes an associative array keyed by the first row. If there is only one row, the header option is ignored.
  • Every value is written as a string, including numbers. Leading and trailing spaces around each value are trimmed.
  • Quotes and backslashes are escaped in the generated code.
  • If a row has fewer values than the header, the missing values become empty strings. If two header names are the same, the later column overwrites the earlier one.

Limitations

  • Quoted CSV fields are not parsed. The tool splits each line at every delimiter, so a value like "Smith, John" is split into two. If your data contains commas inside values, copy it from a spreadsheet and use TSV instead.
  • A value that contains a line break (common in spreadsheet cells) is split into separate rows.

FAQ

Q. How do I convert an Excel range?

A. Select the cells in Excel, copy them (Ctrl+C), paste them into the text box, and choose TSV. Excel puts a tab between columns when you copy.

Q. Is my data uploaded anywhere?

A. No. The conversion runs entirely in your browser.

Q. I only have one column of values.

A. Use Text Lines to Array Code to get a flat list. To start from JSON, use JSON to PHP Array.