CSV to YAML Converter

Convert CSV data to a YAML list of mappings for config files and pipelines

Parses CSV and serialises each row as a YAML mapping, emitting a list of records in block or flow style. Quotes values that need it, infers numbers and booleans optionally, and runs fully in your browser. It runs free in your browser on Gera Tools, with nothing uploaded.

Last updated Source: Gera Tools

What YAML structure does it produce?

A top-level sequence (list) where each item is a mapping of column name to cell value. In block style each row is a `- key: value` block; in flow style each row is an inline `{key: value}` map.

Convert CSV to YAML

This tool turns a CSV file with a header row into a YAML list of mappings — one mapping per row, keyed by the column names. It is handy for generating config files, Ansible vars, CI matrices, or seed data from a spreadsheet export.

How it works

The CSV is parsed with an RFC 4180 scanner so quoted fields with embedded commas, doubled quotes (""), and line breaks are handled correctly. The first row supplies the keys; each later row becomes a mapping in a top-level sequence.

Each value is serialised safely. A scalar is emitted plain (unquoted) only when it is safe to do so; otherwise it is double-quoted with internal quotes and backslashes escaped. This protects values that contain : (colon-space), a leading #, leading or trailing whitespace, or that would otherwise be parsed as a boolean or number. With “infer numbers and booleans” on, clean numeric literals and the words true, false, and null are emitted unquoted as their YAML types.

Example output

Given this CSV:

name,active,score
Alice,true,42.5
Bob,false,

block style with number/boolean inference produces:

- name: Alice
  active: true
  score: 42.5
- name: Bob
  active: false
  score: ""

The empty score for Bob is quoted as an empty string rather than emitted as a bare null, so parsers that require a value receive an explicit empty rather than a missing key.

Tips for common use cases

Config files and Ansible vars — Use block style. The output reads like handwritten YAML and is easy to diff. Turn on number inference so numeric values are usable directly in conditionals and arithmetic.

CI matrices (GitHub Actions matrix strategy) — Prepare a CSV of build combinations (OS, Node version, etc.) and convert to flow style for a compact inline representation. Each row becomes one matrix entry.

Database seed data — If your seed loader reads YAML, converting the canonical spreadsheet directly avoids maintaining two formats. Leave number inference on; turn it off for any column that holds structured codes or IDs.

Phone numbers and leading-zero IDs — Turn off number inference. 0044 1234 5678 would lose the leading zero and 007 would become 7. With inference off, every value is treated as a string and quoted only when structurally necessary.

Use block style for human-readable config you will edit by hand, and flow style when you want compact one-line-per-record output.

Reading the output in code

The resulting YAML is a standard sequence of mappings. Most YAML libraries load it into a list of dictionaries:

# Python
import yaml
with open("data.yaml") as f:
    records = yaml.safe_load(f)
for row in records:
    print(row["name"], row["score"])
// Node.js (with js-yaml)
const yaml = require('js-yaml')
const fs   = require('fs')
const records = yaml.load(fs.readFileSync('data.yaml', 'utf8'))
records.forEach(row => console.log(row.name, row.score))
# Ruby
require 'yaml'
records = YAML.load_file('data.yaml')
records.each { |r| puts r['name'] }

All conversion runs locally — nothing is uploaded.