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.

POSThttps://apibox.io.vn/v1/json-format

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

NameInTypeRequiredDefault
jsonbodystringyesJSON to format, as a string (or any JSON value). A raw text/plain body is also accepted.
indentbody|querynumberno2Spaces per level (0-8), or tab.
minifybody|querybooleannofalseOutput compact JSON without whitespace.
sort_keysbody|querybooleannofalseSort 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}'

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

Start with 1,000 free requests every month. Get free API key →