xtract.bot
POST /api/json-format

Format JSON: pretty-print with indent, minify whitespace, or sort keys lexicographically (deterministic output for hashing & diffs).

Reformats a JSON document. Three modes: - `pretty` (default): indent + newlines, 2 spaces (configurable). - `minify`: no whitespace, smallest possible byte size. - `sort`: pretty output with keys sorted lexicographically at every level. Same input always produces byte-identical output — useful for content fingerprints, hash keys, and clean diffs. Invalid JSON is rejected with a 400 + the parser error position.

Inputs

NameTypeDefaultDescription
input*stringJSON text.
modeenum (pretty | minify | sort)"pretty"Output mode.
indentnumber (1…8)2Indent width in spaces (ignored for `minify`).

Response

Modes: json, text. Cache: yes (24h TTL).

Code samples

Built from the sort-small example.


curl -X POST https://api.xtract.bot/api/json-format \
  -H "Content-Type: application/json" \
  -H "Accept: application/json" \
  -H "X-Account-Id: $XTRACT_ACCOUNT_ID" \
  -H "X-Api-Key: $XTRACT_API_KEY" \
  -d '{
  "input": "{\"zebra\":1,\"alpha\":{\"y\":2,\"x\":3},\"mid\":[1,2,3]}",
  "mode": "sort",
  "indent": 2
}'