Pretty-print JSON with two spaces, four spaces or a tab.
| Endpoint | POST https://astraljson.com/api/v1/json-prettify |
| Auth | Bearer token, free |
| Sends | input: text |
| Returns | result: text |
| option | 2 | 4 | tab |
| Price | Free. 1,000 calls a day, 60 a minute. |
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.
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"}'{
"tool": "json-prettify",
"result": "{\n \"name\": \"astral\",\n \"tools\": [\n \"prettify\",\n \"validate\"\n ],\n \"free\": true\n}",
"chars": 87,
"ms": 1
}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();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"]| Field | Type | Notes |
|---|---|---|
| input | string | Required. Up to 200,000 characters per call. |
| option | string | One of: 2, 4, tab. |
Errors are RFC 7807 problem documents with a stable type you can branch on.
| missing-token | 401 | No Authorization header. |
| bad-request | 400 | input missing or the wrong type. |
| bad-option | 400 | option is not one of the listed values. |
| tool-failed | 422 | The input could not be processed. detail says why. |
| quota-exceeded | 429 | Past 1,000 calls today. |
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