JSON minify API

Strip every space and newline a JSON document does not need.

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

When to call it

Minifying matters where JSON is paid for by the byte: a response body, a queue message, a cookie, a column in a database. Doing it at the edge of your own service rather than by hand means the saving is applied to every document, including the ones nobody remembered to check.

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-minify \
  -H "Authorization: Bearer ast_YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"input": "{\n  \"id\": 42,\n  \"tags\": [ \"a\", \"b\" ]\n}"}'
response
{
  "tool": "json-minify",
  "result": "{\"id\":42,\"tags\":[\"a\",\"b\"]}",
  "chars": 26,
  "ms": 1
}

In your language

JavaScript
const res = await fetch("https://astraljson.com/api/v1/json-minify", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.ASTRAL_TOKEN}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({"input": "{\n  \"id\": 42,\n  \"tags\": [ \"a\", \"b\" ]\n}"}),
});
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-minify",
    headers={"Authorization": f"Bearer {os.environ['ASTRAL_TOKEN']}"},
    json={"input": "{\n  \"id\": 42,\n  \"tags\": [ \"a\", \"b\" ]\n}"},
    timeout=30,
)
res.raise_for_status()
result = res.json()["result"]

Parameters

FieldTypeNotes
inputstringRequired. Up to 200,000 characters per call.

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.
tool-failed422The input could not be processed. detail says why.
quota-exceeded429Past 1,000 calls today.

Questions

How much smaller does it get?
Only the whitespace goes, so the saving is whatever indentation and newlines were costing. On a pretty-printed document that is commonly 15 to 30 percent; on one that was already compact it is nothing.
Is the result still valid JSON?
Yes. It is parsed and re-serialised, so anything that comes back is valid by construction. If the input was not valid, you get a 422 instead.
Does it sort or drop keys?
Neither. Key order is preserved and nothing is removed. If you want a canonical form for comparison, use the compare endpoint instead.

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