Overview
Introduction
A spreadsheet export is easy to scan as a table but awkward to use directly in most YAML-based tooling, fixtures, seed data, config lists. This converter turns CSV with a header row into a YAML sequence of mappings, one per data row, using the header as each mapping's keys.
It's the direct inverse of the YAML to CSV Converter, so round-tripping data through both tools should return you to equivalent structure, modulo the fact that CSV itself has no types, so a round trip through CSV normalizes every value to a string.
What Is CSV to YAML Converter?
A CSV-to-YAML converter reads a delimited table, treats the first row as column headers, and produces a YAML sequence where each subsequent row becomes one mapping keyed by those headers.
It correctly handles RFC 4180 quoting, so fields containing the delimiter, quotes, or embedded newlines are parsed as single values rather than being split incorrectly.
How CSV to YAML Converter Works
A small parser reads the CSV character by character, tracking whether it's inside a quoted field, to correctly split rows and cells even when a field contains the delimiter or a line break.
The first row becomes the set of keys used to build a record object for every subsequent row, and the resulting array of records is serialized as block-style YAML.
When To Use CSV to YAML Converter
Use it when you have a CSV export, from a spreadsheet, a database query, or another tool, and need it as a YAML fixture, seed file, or config list.
It's also useful for quickly reviewing a CSV's structure in a more hierarchical, readable form.
Often used alongside YAML to CSV Converter, TSV to YAML Converter and YAML to JSON Converter.
Features
Advantages
- Runs entirely client-side.
- Correctly parses RFC 4180-quoted fields, including embedded commas and newlines.
- Every record gets a consistent set of keys, even when trailing values are missing.
- Works with comma, semicolon, or tab delimiters.
Limitations
- All values become YAML strings; there's no automatic conversion to numbers or booleans.
- A CSV with no header row will incorrectly treat its first data row as headers.
- Extremely large CSV files may be slow to parse, since the whole file is processed in memory.
Examples
Best Practices & Notes
Best Practices
- Add explicit types after conversion if your target system needs numbers or booleans rather than strings.
- Confirm the CSV has a genuine header row before converting; a headerless file will misread its first record.
- Use the YAML Validator afterward if you plan to hand-edit the result.
Developer Notes
Parsing is done with a small hand-written, quote-aware CSV/TSV tokenizer (tracking an `inQuotes` flag while scanning character by character), not a regex split, since a naive split on the delimiter breaks as soon as a field contains a quoted delimiter or newline. The resulting array of plain objects is passed to the same `stringify()` call the YAML Formatter uses.
CSV to YAML Converter Use Cases
- Turning a spreadsheet export into a YAML seed file for a database or test suite
- Converting tabular data from a CSV report into a YAML-based config list
- Reviewing a wide CSV file's structure in a more readable, hierarchical form
Common Mistakes
- Pasting a CSV without a header row and getting the first data row treated as column names instead.
- Expecting numeric-looking values to convert to real YAML numbers automatically, when CSV has no types to draw that distinction from.
Tips
- If a column header is blank in the source CSV, check the output for a generic `column_N` key in its place.
- Pair this with the YAML to CSV Converter to round-trip and confirm a conversion.