CSV to YAML

Turn CSV rows into a YAML list of records.

Reverse
Input
CSV input
Output
Result
Options

Detected automatically unless you pick one.

Values with leading zeros stay strings so IDs are preserved.

Spaces per level of nesting.

About this tool


Each CSV row becomes one entry in a YAML sequence, with the header row supplying the keys. The result is the list-of-records shape used for fixtures, seed data and inventory files.

YAML is a good target for data that humans will edit afterwards, because it tolerates comments and multi-line strings. Both impossible in CSV.

How to use it

  1. Paste or upload CSVDrop a .csv file onto the input pane, use the file picker, or paste the text directly.
  2. Adjust the options if neededThe defaults suit most input. Open Options to change how values are interpreted or formatted.
  3. ConvertPress Convert to YAML, or use Ctrl+Enter (Cmd+Enter on macOS).
  4. Read any warningsWarnings explain anything that could not be represented exactly in the target format.
  5. Copy or downloadCopy the result, or download it as a .yaml file.

Worked examples


Each example below is executed against this tool by the test suite, so what you see is what the tool actually produces.

CSV to YAML

Input

id,name,zip
1,Alice,01234
2,Bob,56789

Output

- id: 1
  name: Alice
  zip: "01234"
- id: 2
  name: Bob
  zip: 56789

The zip code with a leading zero stays a quoted string, because dropping the zero would corrupt it. The other parses as a plain number, since nothing about it needs protecting.

What to watch for


The details that decide whether a conversion is correct, and where information can be lost without any error being raised.

Rows become sequence entries
Every data row is written as a hyphen-prefixed mapping, with keys taken from the header. Reading the output is much easier than reading the CSV when rows have many columns, since each field appears on its own line with its name.
Type inference, and why quoting appears
Numbers and booleans are converted to real YAML types. Values that must stay strings are quoted automatically: "01234" keeps its leading zero and "true" stays a string rather than becoming a boolean. That quoting is what makes the conversion safe to reverse.
Values with newlines become block scalars
A quoted CSV field containing a line break is written as a YAML block scalar, so the text stays readable across several lines instead of being crammed into one escaped string.
Duplicate headers are made unique
YAML mappings cannot repeat a key, so a duplicated column name is suffixed, two "name" columns become name and name_2, and blank headers become column_1, column_2 by position.

Limitations


  • The output is always a flat sequence of mappings; CSV has no nesting to express.
  • Comments cannot be generated, as the CSV source has none.
  • Processing happens in your browser, so very large inputs are bounded by available memory. Files above roughly 10 MB are handled but will feel slower, and multi-hundred-megabyte files are better suited to a command-line tool.

Questions


Why are some values quoted and others not?
Quotes are added only where YAML would otherwise change the type, leading zeros, the words true and false, and anything that looks like a number but should stay text.
Can I add comments afterwards?
Yes, and that is often the reason to convert. YAML supports # comments, so the output can be documented in a way the CSV could not be.