SQL Beautifier API

Format and beautify SQL queries online. Supports PostgreSQL, MySQL, SQLite, SQL Server and Oracle. Keyword casing and custom indentation. 100% client-side.

The SQL Beautifier is also available as a free REST API. Send a POST request with a JSON body to https://dot.tools/api/tools/sql-beautify — no authentication, no API key, CORS enabled. Successful calls return { "ok": true, "result": { … } }; failures return HTTP 400 or 422 with an error body.

Request body

FieldTypeRequiredDescription
sqlstringrequiredThe SQL query or script to format.
dialect"sql" | "postgresql" | "mysql" | "mariadb" | "sqlite" | "transactsql" | "plsql"requiredThe SQL dialect to parse and format for.
keywordCase"preserve" | "upper" | "lower"requiredLetter case applied to SQL keywords.
indentSizeintegerrequiredNumber of spaces per indentation level.

Response

FieldTypeRequiredDescription
sqlstringrequiredThe formatted SQL.

Example request

curl -X POST https://dot.tools/api/tools/sql-beautify \
  -H 'Content-Type: application/json' \
  -d '{
  "sql": "select u.id, u.email, count(o.id) as order_count, sum(o.total) as lifetime_value from users u left join orders o on o.user_id = u.id and o.status != 'cancelled' where u.created_at > '2024-01-01' and (u.country = 'NL' or u.country = 'BE') group by u.id, u.email having count(o.id) > 2 order by lifetime_value desc limit 25;",
  "dialect": "postgresql",
  "keywordCase": "upper",
  "indentSize": 2
}'

Sample response

{
  "ok": true,
  "result": {
    "sql": "SELECT\n  u.id,\n  u.email,\n  count(o.id) AS order_count,\n  sum(o.total) AS lifetime_value\nFROM\n  users u\n  LEFT JOIN orders o ON o.user_id = u.id\n  AND o.status != 'cancelled'\nWHERE\n  u.created_at > '2024-01-01'\n  AND (\n    u.country = 'NL'\n    OR u.country = 'BE'\n  )\nGROUP BY\n  u.id,\n  u.email\nHAVING\n  count(o.id) > 2\nORDER BY\n  lifetime_value DESC\nLIMIT\n  25;"
  }
}

Use the free SQL Beautifier in your browser, read the SQL Beautifier guide, or import the full OpenAPI specification.