CSV to YAML Converter

Data rows—
Columns—
Status—

How CSV to YAML Converter is calculated: CSV: the header row becomes the keys, each row becomes one YAML mapping. YAML: a list of mappings becomes a header row plus one CSV row each.

What is a CSV to YAML converter?

A CSV to YAML converter turns spreadsheet rows into YAML lists, and back again. A table of names, ages, and cities becomes a YAML list of mappings — one mapping per row, with the header as the keys. The default CSV here has 2 rows and 3 columns, and converts to a YAML list of 2 items.

The need comes up wherever data moves between a spreadsheet and a config file. A product list kept in a spreadsheet needs to become a YAML file for a static site; a YAML list in a config needs to become a spreadsheet so a non-technical colleague can edit it. Converting by hand means retyping every row, which is slow and invites typos.

This tool works in both directions in one place. Paste CSV and get YAML, or paste YAML and get CSV, with the same parser both ways. It uses js-yaml, version 4.1.0, vendored on this site, with a built-in subset parser as a fallback — and everything runs in your browser, so your data never leaves your device.

How CSV to YAML conversion works

The first row of the CSV is the header, and its values become the keys. Each following row becomes one mapping: the first column's value goes under the first key, the second under the second, and so on. The default file has the header name, age, city, so Ada's row becomes a mapping with name Ada, age 36, and city London.

Values are typed automatically. "36" becomes the number 36, "true" becomes the boolean true, and "London" stays a string. That matters because a YAML consumer expects a number for an age, not the string "36". The YAML output uses two-space indentation, with each mapping starting with a dash.

Quoted fields are honoured on the way in: a value with a comma inside it, written in quotes, stays one field. On the way back, values that contain a comma, a quote, or a line break are quoted again, so the CSV that comes out is valid and round-trips cleanly.

Headers and rows, explained

The header is the contract. It names the columns, and every row must have the same number of values as the header has names. A row with too few values gets an empty string for the missing keys; a row with too many has the extras ignored, which is a sign the file needs checking first — count the values in each row against the header before converting.

The YAML side is a list of mappings, one per row. Each mapping starts with "- " and its keys are indented two spaces. That shape is the standard way to write a table in YAML, and it is the shape most tools expect when they read a list of records.

Going back, the converter takes the keys of the first mapping as the header, then writes one CSV row per mapping. Mappings with different keys produce empty cells for the missing keys, so a ragged YAML list still converts — but the result is only as clean as the input, so keep the keys consistent.

The header row is the contract, and the converter trusts it completely. Every value in a row is attached to the header above it, so a header spelt two ways — Name in one file and name in another — produces two different keys, and a program reading the YAML will treat them as different fields. The fix is to clean the headers before converting: make them consistent, lower-case, and free of spaces, because a key with a space in it is legal YAML but awkward to use in a program. The converter does not rename headers; it uses them exactly as written.

A worked example: a table becomes a list

Take the default CSV: "name,age,city" then "Ada,36,London" and "Grace,40,Paris". That is 2 rows and 3 columns. Convert it and you get a YAML list of 2 mappings: the first starts with "- name: Ada", then " age: 36" and " city: London" underneath, and the second does the same for Grace.

Reverse it: paste that YAML back, switch the direction to YAML to CSV, and you get the original table — header first, then one row per person. The round trip is exact for values, which is the test of a good converter. Try it with a quoted value, such as a city written as "New York, NY" in quotes, and the comma stays inside the field on both trips.

Try an error to see the boundary: YAML that is a single mapping instead of a list fails, because a list is required — the output reports that the YAML must be a list of objects. The tool reports the problem rather than guessing, because a guessed conversion of a data file is worse than no conversion.

Who uses a CSV to YAML converter, and why

Developers building static sites are the main users. A product list, a team page, or a price table kept in a spreadsheet needs to become a YAML data file for the site generator, and the converter does it in one paste. Editing the spreadsheet and re-converting is faster than editing YAML by hand.

Data analysts are the second group. A YAML list from a config file needs to become a spreadsheet so it can be sorted, filtered, and shared with colleagues who do not write YAML. Converting back lets the edited spreadsheet return to the config.

Anyone moving a small table between tools is a third group. A mailing list, a stock list, or a class register all travel as CSV, and all of them sometimes need to live in a YAML file. A CSV to JSON converter covers the same need for JSON.

Content teams are a third group. A spreadsheet of products, articles, or FAQs is easy to edit in a table, but the site that publishes it wants YAML, and converting by hand is slow and error-prone. The converter is the bridge: edit in the spreadsheet, export as CSV, convert to YAML, and paste the result into the site. The round trip works because the table and the YAML hold the same data — the table is just the easier shape to edit.

CSV to YAML vs other converters

CSV to YAML and CSV to JSON do the same job in different formats. The CSV to JSON converter on this site turns the same table into a JSON array, which suits APIs and JavaScript, while this tool turns it into YAML, which suits configs and static sites. The data is the same; the format is the choice.

YAML is the more readable of the two for a human. A YAML list can be read at a glance, while the same data as JSON is wrapped in braces and brackets. JSON is the better choice for a program to read. Pick the format your consumer wants, and convert the same CSV either way.

A JSON formatter tidies JSON that is already JSON, and a YAML to JSON converter moves YAML to JSON. The three tools together cover every direction a table of data might need to travel.

A converter is not a validator, and the distinction matters when the input is messy. A converter assumes the CSV is well formed and does its best with what it is given, filling gaps and ignoring extras without complaint. A validator checks the CSV first and reports every problem, which is the right tool when the file came from an export you do not trust. Use the validator to find the problems and the converter to do the conversion — the two tools do different jobs, and using them in that order saves a debugging session.

Common CSV to YAML mistakes

The first mistake is a header with duplicate names. Two columns both called "name" produce a mapping with one name key, and the second value overwrites the first. Give every column a distinct name before converting.

Second: values that look like numbers but are not. A product code such as "007" converts to the number 7, losing the leading zeros. Quote values that must stay strings, or fix them after conversion — the converter follows the standard typing rule, and the rule is the trap.

Third: ragged rows. A row with fewer values than the header gets empty strings for the missing keys, which is silent data loss. Validate the CSV first — the validator names the short rows — and fix them before converting.

Fourth: expecting nested data. CSV is flat: one row, one level. A YAML list of mappings with nested objects inside cannot become CSV without flattening, because a spreadsheet has no nesting. If your data is nested, keep it in YAML or JSON.

A second mistake is converting a file with ragged rows and hoping the YAML will be fine. A row with too few values gets an empty string for the missing keys, which is honest but can hide a real error — a missing price looks like a zero price, and a missing name looks like an empty name. A row with too many values has the extras ignored, which silently drops data. The safe habit is to validate the CSV first, or at least to count the values in each row against the header, before converting.

How to use this CSV to YAML converter

Paste your CSV into the box — the default has 2 rows and 3 columns — and pick the direction. CSV to YAML is the default. The converted output appears instantly in the box below, with the row and column counts above it.

To convert the other way, paste a YAML list of mappings and switch the direction to YAML to CSV. To copy the result, use the Copy button next to the output box. If the input has an error, the output names the problem — fix it and paste again.

Everything runs in your browser. No sign-up, no account, no data sent anywhere — your data never leaves your device. It works offline once the page has loaded, because the js-yaml library is vendored on this site rather than fetched from a CDN.

Paste the CSV, press convert, and read the YAML before you copy it. The output is a list of mappings, one per row, and the first mapping should have exactly the keys from the header — count them, because a header with a duplicate name will produce a mapping with a repeated key, and the second value will win. When the first mapping looks right, scroll through the rest and check that the values line up under the right keys, then copy the YAML into the config file or document it belongs to.

Frequently Asked Questions

The keys. The first row of the CSV names the columns, and each following row becomes one mapping with those keys. The default file has the header name, age, city, so Ada's row becomes a mapping with name Ada, age 36, and city London.

Yes. The value 36 becomes the number 36, and true becomes the boolean true. A value that must stay a string, such as a product code 007, should be quoted — otherwise it converts to the number 7 and loses its leading zeros.

Yes — switch the direction to YAML to CSV. The YAML must be a list of mappings; the keys of the first mapping become the header, and each mapping becomes one CSV row. Values with commas are quoted so the CSV stays valid.

Short rows get empty strings for the missing keys, which is silent data loss. Validate the CSV first with the CSV validator, which names the short rows, and fix them before converting.

More free tools

More calculators and utilities from Sortrun — free, no sign-up.