Convert CSV to YAML (For Config Files)
Convert CSV data to YAML format. Perfect for DevOps configuration files, Kubernetes manifests, and static site data.
Convert CSV to YAML (For Config Files)
YAML (YAML Ain't Markup Language) is the standard for configuration files today. Kubernetes, Ansible, Docker Compose, Jekyll/Hugo front matter—they all use YAML.
Sometimes you have a spreadsheet of configurations (e.g., a list of users, ports, or redirects) that you need to convert into a YAML file.
The Format Difference
CSV:
name,role,port
app-1,web,80
app-2,db,5432
YAML (List of Objects):
- name: app-1
role: web
port: 80
- name: app-2
role: db
port: 5432
YAML relies on indentation. It is cleaner to read than JSON or XML.
Method 1: Python (Pandas or PyYAML)
The easiest way to automate this.
import pandas as pd
import yaml
# Read CSV
df = pd.read_csv('data.csv')
# Convert to dict
data = df.to_dict(orient='records')
# Dump to YAML
with open('data.yaml', 'w') as f:
yaml.dump(data, f, sort_keys=False)
Method 2: Online Converter
For quick copy-paste jobs.
Handling Nested Data
CSV is flat. YAML is often nested.
CSV:
server,env.name,env.cpu
web01,prod,4
Desired YAML:
- server: web01
env:
name: prod
cpu: 4
Most simple converters will produce keys with dots ("env.name": "prod").
To get true nesting, you need a script that parses the dot-notation in headers and builds a nested dictionary.
Data Types
YAML is smart about types.
truebecomes boolean.123becomes integer.123.45becomes float.2024-01-01becomes date.
Gotcha:
If you have a version number like 1.10, YAML might read it as a float 1.1.
Fix: Quote it in the CSV or force string type in your converter to keep it as "1.10".
Summary
- YAML is great for config.
- Use Python/Pandas for robust conversion.
- Watch out for indentation (2 spaces is standard).
- Be careful with type inference on version numbers.
Config files from spreadsheets? HappyCSV converts CSV to clean, valid YAML instantly.
Related Articles
Convert CSV to HTML Table
Convert CSV files to HTML table code for websites. Free online tool with proper escaping and semantic markup.
Convert CSV to Markdown Table
Convert CSV files to Markdown tables for GitHub README files, documentation, and blog posts. Free online tool.
Convert TSV to CSV (Tab-Separated to Comma-Separated)
Convert TSV files to standard CSV format. Free online converter for tab-delimited data. Works with Excel exports.
Need to handle CSV files?
HappyCSV is the free, secure way to merge, split, and clean your data — all in your browser.