JSON Formatter API
Pretty print JSON with 0-8 spaces or tabs, minify it, or sort object keys recursively. Syntax errors are reported with line and column.
Send a JSON document in json (preferably as a string) or as a raw text/plain body, and get the formatted text back in result with its length in characters. By default the output is indented with 2 spaces; set indent to a number from 0 to 8 or to tab, or use minify=true to remove all whitespace.
With sort_keys=true the keys of every object are sorted alphabetically at all depths, which makes diffs and hashes of JSON stable. Arrays keep their order.
If the input is not valid JSON the response is valid: false with a parse_error (message, position, line and column when available) instead of an HTTP error. The request body is limited to 5 MB.
Parameters
| Name | In | Type | Required | Default | |
|---|---|---|---|---|---|
json | body | string | yes | JSON to format, as a string (or any JSON value). A raw text/plain body is also accepted. | |
indent | body|query | number | no | 2 | Spaces per level (0-8), or tab. |
minify | body|query | boolean | no | false | Output compact JSON without whitespace. |
sort_keys | body|query | boolean | no | false | Sort object keys alphabetically at every depth. |
Example
curl -X POST "https://apibox.io.vn/v1/json-format" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"json":"{\"b\":2,\"a\":{\"d\":[1,2],\"c\":true}}","sort_keys":true}'const res = await fetch('https://apibox.io.vn/v1/json-format', {
method: 'POST',
headers: {
Authorization: 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json',
},
body: JSON.stringify({
"json": "{\"b\":2,\"a\":{\"d\":[1,2],\"c\":true}}",
"sort_keys": true
}),
});
const data = await res.json();
console.log(data);import requests
res = requests.post(
"https://apibox.io.vn/v1/json-format",
headers={"Authorization": "Bearer YOUR_API_KEY"},
json={"json": "{\"b\":2,\"a\":{\"d\":[1,2],\"c\":true}}", "sort_keys": True},
timeout=30,
)
print(res.json())<?php
$ch = curl_init('https://apibox.io.vn/v1/json-format');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_HTTPHEADER => ['Authorization: Bearer YOUR_API_KEY', 'Content-Type: application/json'],
CURLOPT_POSTFIELDS => '{"json":"{\\"b\\":2,\\"a\\":{\\"d\\":[1,2],\\"c\\":true}}","sort_keys":true}',
]);
$response = curl_exec($ch);
print_r(json_decode($response, true));Response
{
"valid": true,
"result": "{\n \"a\": {\n \"c\": true,\n \"d\": [\n 1,\n 2\n ]\n },\n \"b\": 2\n}",
"characters": 75
}
Use cases
- Beautify minified API responses for debugging
- Minify JSON before storing or sending it
- Normalize JSON with sorted keys for stable diffs and hashes
- Format JSON config files in scripts and CI jobs
FAQ
How do I minify JSON?
Send minify=true. The result has no spaces or line breaks.
Can I indent with tabs?
Yes, set indent=tab. Numbers from 0 to 8 set the number of spaces (default 2).
What happens with invalid JSON?
The response is {"valid": false, "parse_error": {...}} with the error message and, when available, the position, line and column.
Related APIs
JSON Validator
Check JSON syntax with exact line and column of errors, and validate data against a JSON Schema (draft 4, 7, 2019-09 or 2020-12).
CSVCSV to JSON
Convert CSV into an array of JSON objects using the header row, with delimiter auto-detection, number and boolean typing, and row-level errors.
J→CJSON to CSV
Convert a JSON array of objects or arrays into CSV with a header row and a custom delimiter, returned as JSON or as a downloadable text/csv file.