YAML to SQL

Convert YAML to SQL instantly in your browser.

Local Your input is processed locally in your browser. Found a problem? Report an issue

What YAML to SQL does

YAML to SQL reads YAML and writes it as SQL. The input is parsed first, so a syntax error is reported with its position instead of producing broken output.

YAML is a human-friendly data format based on indentation, used for configuration files such as Docker Compose, Kubernetes and GitHub Actions. SQL INSERT statements add rows to a database table. Running them in MySQL, PostgreSQL, SQLite or SQL Server loads the data.

YAML to SQL example

Input

- id: 1
  name: Ada
- id: 2
  name: Lin

Output

-- Table name: data. Rename it to match your database.
INSERT INTO data ("id", "name") VALUES (1, 'Ada');
INSERT INTO data ("id", "name") VALUES (2, 'Lin');

The output is what this tool produces for the input above it.

How it works

Reading YAML. The YAML is parsed with js-yaml. A list of mappings gives one row per item.

Writing SQL. Each record becomes one INSERT INTO data (...) VALUES (...); statement. Column names are the keys of the records, with nested objects flattened into dotted names and quoted as identifiers. Text is put in single quotes with any single quote doubled, numbers are written as numbers, true and false become TRUE and FALSE, and missing values become NULL.

Details and limits

  • Everything runs on your device, so there is no upload and no fixed size limit; very large inputs depend on its memory.
  • It works in current browsers on phones, tablets and computers, and it is free with no account.
  • The table is named data. Change the name, and add a CREATE TABLE statement if the table does not exist yet.
  • Numbers are detected only when the whole value is a plain number such as 42 or 3.5.

Questions

Is my data uploaded?

No. The conversion runs in your browser.

Is YAML to SQL free?

Yes, with no sign-up and no limit on use.

Which databases accept the output?

MySQL, MariaDB, PostgreSQL, SQLite and SQL Server all accept these INSERT statements. Column names are in double quotes, the SQL standard; in MySQL, turn on ANSI_QUOTES or replace them with backticks.

Can I convert SQL back to YAML?

Not with this tool. To get rows out of a database, export the query result as CSV or JSON from your database client.