JSON Formatter API
Format, beautify, minify, and validate JSON online. Custom indentation, key sorting, and precise error locations. 100% client-side — your data never leaves your browser.
The JSON Formatter is also available as a free REST API. Send a POST request with a JSON body to https://dot.tools/api/tools/json-formatter — 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
| Field | Type | Required | Description |
|---|---|---|---|
mode | "beautify" | "minify" | "validate" | required | Beautify with indentation, minify to a single line, or validate only. |
input | string | required | The JSON text to format, minify, or validate. |
indent | "2" | "4" | "tab" | required | Indentation used when beautifying: 2 spaces, 4 spaces, or tabs. |
sortKeys | boolean | required | Sort object keys alphabetically (recursively) before output. |
Response
| Field | Type | Required | Description |
|---|---|---|---|
output | string | required | The formatted JSON, or the original input in validate mode. Empty when invalid. |
valid | boolean | required | Whether the input is valid JSON. |
error | unknown | required | Parse error message when invalid. |
errorLine | unknown | required | 1-based line of the parse error when invalid. |
errorColumn | unknown | required | 1-based column of the parse error when invalid. |
Example request
curl -X POST https://dot.tools/api/tools/json-formatter \
-H 'Content-Type: application/json' \
-d '{
"mode": "beautify",
"indent": "2",
"sortKeys": false,
"input": "{\"name\":\"dot.tools\",\"version\":\"2.0.0\",\"private\":true,\"tools\":[\"json-formatter\",\"xml-formatter\",\"yaml-json\"],\"meta\":{\"clientSide\":true,\"category\":\"format\"}}"
}'Sample response
{
"ok": true,
"result": {
"output": "{\n \"name\": \"dot.tools\",\n \"version\": \"2.0.0\",\n \"private\": true,\n \"tools\": [\n \"json-formatter\",\n \"xml-formatter\",\n \"yaml-json\"\n ],\n \"meta\": {\n \"clientSide\": true,\n \"category\": \"format\"\n }\n}",
"valid": true,
"error": null,
"errorLine": null,
"errorColumn": null
}
}Use the free JSON Formatter in your browser, read the JSON Formatter guide, or import the full OpenAPI specification.