JSON formatter API

Pretty-print JSON with two spaces, four spaces or a tab.

EndpointPOST https://astraljson.com/api/v1/json-prettify
AuthBearer token, free
Sendsinput: text
Returnsresult: text
option2 | 4 | tab
PriceFree. 1,000 calls a day, 60 a minute.

When to call it

Formatting in a script is nearly always about making a diff readable. Config files, fixtures and recorded API responses arrive on one line because a machine wrote them, and a human then has to review them. Running every one of them through the same indentation in a pre-commit hook or a CI step is what makes the next diff show the change rather than the reformat.

For a one-off, the browser version needs no token and never sends your data anywhere: it runs on your own machine.

Example

curl
curl -X POST https://astraljson.com/api/v1/json-prettify \
  -H "Authorization: Bearer ast_YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"input": "{\"name\":\"astral\",\"tools\":[\"prettify\",\"validate\"],\"free\":true}", "option": "2"}'
response
{
  "tool": "json-prettify",
  "result": "{\n  \"name\": \"astral\",\n  \"tools\": [\n    \"prettify\",\n    \"validate\"\n  ],\n  \"free\": true\n}",
  "chars": 87,
  "ms": 1
}

In your language

JavaScript
const res = await fetch("https://astraljson.com/api/v1/json-prettify", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.ASTRAL_TOKEN}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({"input": "{\"name\":\"astral\",\"tools\":[\"prettify\",\"validate\"],\"free\":true}", "option": "2"}),
});
if (!res.ok) throw new Error((await res.json()).detail);
const { result } = await res.json();
Python
import os, requests

res = requests.post(
    "https://astraljson.com/api/v1/json-prettify",
    headers={"Authorization": f"Bearer {os.environ['ASTRAL_TOKEN']}"},
    json={"input": "{\"name\":\"astral\",\"tools\":[\"prettify\",\"validate\"],\"free\":true}", "option": "2"},
    timeout=30,
)
res.raise_for_status()
result = res.json()["result"]

Parameters

FieldTypeNotes
inputstringRequired. Up to 200,000 characters per call.
optionstringOne of: 2, 4, tab.

Errors

Errors are RFC 7807 problem documents with a stable type you can branch on.

missing-token401No Authorization header.
bad-request400input missing or the wrong type.
bad-option400option is not one of the listed values.
tool-failed422The input could not be processed. detail says why.
quota-exceeded429Past 1,000 calls today.

Questions

What indentation can I ask for?
Two spaces (the default), four spaces, or a tab. Send "option": "2", "4" or "tab". Anything else is refused with a bad-option error rather than silently falling back.
Does it change my data?
No. It parses the document and prints it again, so whitespace changes and nothing else. Key order is preserved exactly as it arrived.
What happens if the JSON is invalid?
You get a 422 with a message naming the line and column of the first fault, the same message the validator endpoint returns.

Other endpoints

A token takes thirty seconds

Free, no card, 1,000 calls a day, and the same token works on astraltext.com, astralpdf.com, astraljson.com and astralbatch.com.

Get a free token