Code Formatter

Format and beautify source code in Python, JSON, XML, HTML, and SQL.

POST 1 credit /v1/code-format
curl -X POST "https://devtools.toolkitapi.io/v1/code-format" \
  -H "Content-Type: application/json" \
  -d '{"code": "{\"name\":\"Alice\",\"age\":30}", "language": "json"}'
import httpx

resp = httpx.post(
    "https://devtools.toolkitapi.io/v1/code-format",
    json={"code": "{\"name\":\"Alice\",\"age\":30}", "language": "json"},
)
print(resp.json())
const resp = await fetch("https://devtools.toolkitapi.io/v1/code-format", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
  },
  body: JSON.stringify({"code": "{\"name\":\"Alice\",\"age\":30}", "language": "json"}),
});
const data = await resp.json();
console.log(data);
# See curl example
Response 200 OK
{
  "formatted": "{\n  \"name\": \"Alice\",\n  \"age\": 30\n}",
  "language": "json"
}

Try It Live

Live Demo

Description

Format and beautify source code in Python, JSON, XML, HTML, and SQL.

How to Use

1

1. Send a POST request with `code` (the source code) and `language` (the target language).

2

2. The `formatted` field contains the beautified output.

About This Tool

Code Formatter beautifies source code in five languages: Python (via autopep8), JSON, XML, HTML (via BeautifulSoup), and SQL (via sqlparse). Paste your code and get clean, consistently formatted output.

Why Use This Tool

Frequently Asked Questions

Which formatting tools are used?
- **Python** — autopep8 (PEP 8 compliance) - **JSON** — Python `json.dumps` with 2-space indent - **XML** — `xml.dom.minidom` pretty printer - **HTML** — BeautifulSoup prettify - **SQL** — sqlparse with reindent and uppercase keywords
Does it validate the code?
Partially. If the code can't be parsed (e.g., invalid JSON or malformed XML), an error is returned. The tool doesn't perform semantic validation.

Start using Code Formatter now

Get your free API key and make your first request in under a minute.