Convert SQL query results to YAML format
Convert SQL query results to YAML format instantly with our free online SQL to YAML converter. This tool helps developers transform SQL data into YAML for configuration files and data serialization. Simply paste your SQL results and get YAML output in real-time.
Convert SQL query result tables to YAML (YAML Ain't Markup Language) format.
Supported formats:
id | name | ageid,name,ageFeatures:
SQL to YAML converter transforms SQL query results into YAML format. YAML is human-readable and commonly used for configuration files. Great for readable data exports, configuration management, and documentation purposes.
Each row becomes a YAML mapping with column names as keys. Lists represent multiple rows. YAML's indentation-based syntax creates clean, readable output. Handles strings, numbers, booleans, and nulls natively.
YAML 1.2 spec is JSON-superset. Strings containing special chars need quoting. Multi-line strings use | (literal) or > (folded). Null is explicit null keyword. Indentation is significant (spaces only, typically 2).
Export database settings as YAML config.
Create readable test data files.
Human-readable data for documentation.
Generate YAML for DevOps tools.
function yamlValue(value) {
if (value === null) return 'null';
if (typeof value === 'number') return value;
if (typeof value === 'boolean') return value;
const str = String(value);
// Quote if contains special chars or looks like other types
if (/^[\d.]+$/.test(str) || /[:#{}[\],&*?|<>=!%@`]/.test(str) ||
str === 'true' || str === 'false' || str === 'null' ||
str.includes('\n')) {
return '"' + str.replace(/"/g, '\\"') + '"';
}
return str;
}
function sqlToYAML(tableName, columns, rows) {
let yaml = `${tableName}:\n`;
rows.forEach(row => {
yaml += ' -\n';
columns.forEach((col, i) => {
yaml += ` ${col.name}: ${yamlValue(row[i])}\n`;
});
});
return yaml;
}
// Output:
// users:
// -
// id: 1
// name: John
// active: trueRepresent rows as list items, handle special characters and types appropriately.
Use SQL to YAML for configuration exports, readable test data, documentation, and DevOps tooling like Ansible or Kubernetes.
Quote if: starts with special char (@, `, *, etc.), looks like number/boolean, contains colon-space, or has leading/trailing spaces. When in doubt, quote.