JSON Minifier
Online JSON Minifier tool will help you compress your JSON data by simply load your JSON and it will be instantly minified.
SQL Formatter & Beautifier is a free tool to format and beautify SQL queries with customizable indentation, keyword case transformation, intelligent formatting, and built-in validation.
SQL queries have a remarkable ability to become unreadable the moment they escape their original context. Copy-paste a query from somewhere, compress it for efficiency, pull it out of minified application code, or inherit it from a colleague who values brevity over clarity, and you end up with something like this:
SELECT u.id, u.name, COUNT(o.id) as order_count FROM users u LEFT JOIN orders o ON u.id=o.user_id WHERE u.created_at > DATE_SUB(NOW(), INTERVAL 30 DAY) AND u.status='active' GROUP BY u.id, u.name HAVING COUNT(o.id) > 5 ORDER BY order_count DESC LIMIT 10;
Formatting it by hand, adding line breaks in the right places, consistent indentation, and proper spacing, is tedious work that produces no value. This tool formats it instantly and lets you choose how the formatting happens.
The core operation is mechanical: add line breaks at logical boundaries, indent clauses consistently, apply consistent spacing around operators, and optionally transform keywords to a consistent case. The result is a query that is genuinely readable without any change to functionality.
The same query formatted becomes:
SELECT
u.id,
u.name,
COUNT(o.id) AS order_count
FROM users u
LEFT JOIN orders o
ON u.id = o.user_id
WHERE
u.created_at > DATE_SUB(NOW(), INTERVAL 30 DAY)
AND u.status = 'active'
GROUP BY u.id, u.name
HAVING COUNT(o.id) > 5
ORDER BY order_count DESC
LIMIT 10;
The functionality is identical. The readability is transformed. Understanding what the query does at a glance becomes possible. Spotting errors becomes easier. Code review becomes feasible rather than an act of faith.
Indentation level. Whether to use two spaces, four spaces, tabs, or no indentation at all. Consistency matters more than the specific choice. The tool lets you match the indentation convention of your codebase.
Keyword case. SQL keywords like SELECT, FROM, WHERE, GROUP BY can be formatted in uppercase (standard for decades), lowercase (modern preference), or mixed case. This is purely aesthetic and does not affect functionality. The uppercase convention, dating from the era when SQL was taught in uppercase, is the most common in legacy code. Lowercase is increasingly preferred in modern code because it is easier to read in contexts where uppercase carries significance like class names and constants.
Spacing around operators. Whether to add spaces around comparison operators, mathematical operators, and commas. WHERE x=5 versus WHERE x = 5 is the difference here. The formatted version is more readable but takes slightly more space.
Clause positioning. Whether to break SELECT clauses across multiple lines with one column per line, or keep them on fewer lines if they fit. This is the trade-off between comprehensiveness and compactness. One column per line is easier to read and makes diffs cleaner when columns are added or removed. Fewer lines is more compact for simple queries.
Trailing semicolon. Whether the output should end with a semicolon. Most database clients require it, some are indifferent. SQL formatting tools often make this configurable because some people have strong opinions about whether trailing punctuation is necessary.
Built-in validation confirms the input is valid SQL before the formatting runs, which catches syntax errors early rather than producing confusing output from malformed input.
The tool processes everything client-side in your browser. Queries containing sensitive data, proprietary business logic, or internal systems are not transmitted to any server.
Understanding the sources of unreadable SQL helps explain why this task comes up as often as it does.
Minified application code. Web applications frequently minify JavaScript, but SQL queries embedded in that code sometimes get minified along with it, producing dense, hard-to-read queries that are functional but opaque.
Database logging and query capture. Database systems log queries, but the logged format is often the raw query string without formatting. Extracting a query from logs and needing to understand what it does requires reading it in its raw form.
Generated queries from ORMs. Object-relational mapping frameworks generate SQL dynamically based on query builders or lambda expressions. The generated queries are syntactically correct but often compressed and unformatted because formatting is an optimization choice in the code generator.
Legacy code and inherited queries. Queries written years ago in codebases with different standards, or inherited from colleagues who had different preferences, carry formatting that does not match current conventions.
Copy-paste from multiple sources. Assembling a query from multiple pieces found in documentation, previous queries, or examples often produces inconsistent formatting even before concatenation happens.
Formatting SQL is rarely an end goal in itself. It usually appears as a step in a larger workflow.
Code review and auditing. Reviewing SQL in pull requests or doing a security audit of queries is infinitely easier on formatted SQL. The formatting surfaces the logic that minified SQL obscures.
Debugging slow queries. When a query is slow, understanding what it does is the first step. Formatting it is often the second. Tools like database query analyzers frequently output unformatted explain plans and query logs. Formatting them makes analysis clearer.
Documentation and knowledge transfer. Documenting how the system actually queries its data requires readable SQL. Formatting complex queries before putting them in documentation improves their utility.
Migration and refactoring. Converting queries between databases or refactoring them to work with a different schema requires understanding them first. Formatting them is useful preparation for that work.
A few patterns of formatting that produce correct SQL but suboptimal readability worth being aware of.
Putting too many clauses on one line. Readable SQL breaks most clauses onto their own lines. SELECT a, b FROM table WHERE x = 5 GROUP BY a, b is valid but harder to scan than the same query with each clause on its own line.
Inconsistent indentation of subqueries. Subqueries should be indented consistently to show the nesting level. A subquery in a FROM clause should be more indented than the main query. Inconsistent or missing indentation flattens the visual hierarchy.
Poor alignment of join conditions. When joining multiple tables, the join conditions should be aligned and indented to show they belong together. A proper format makes it immediately clear which tables are joined to which.
Keyword case inconsistency. Mixing uppercase and lowercase keywords within the same query is readable mistakes that happen in hand-written SQL. Formatting with a consistent case preference prevents this.
No. Formatting only changes whitespace, spacing, and optionally keyword case. The query behaves identically before and after formatting. This is the entire value: readability improvement with no risk to functionality.
Yes. The tool processes everything client-side and handles large queries efficiently. Extremely complex queries with dozens of subqueries and joins format correctly. For automated, repeated formatting across many queries, command-line tools or IDE plugins may be more convenient.
The tool handles standard SQL that is compatible across most databases. Dialect-specific features may not be recognized by all formatters. Testing the output is recommended if you are using database-specific functions or syntax.
Yes. Consistency is worth it. Pick a formatting standard and apply it to all SQL in your codebase. This makes reviews easier, auditing simpler, and understanding existing queries faster.
Yes. Built-in validation confirms the input is valid SQL before formatting. If the query has syntax errors, the validation catches them before the formatter runs, preventing confusing output from malformed input.