JSON validator API

Check a document and report the line and column of the first fault.

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

When to call it

Validating in a pipeline is how bad JSON stops before it reaches the thing that will choke on it: a config deploy, a data import, a webhook payload you did not write. Because the answer comes back as a report rather than an exception, a build step can decide what to do with it instead of dying on it.

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-validator \
  -H "Authorization: Bearer ast_YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"input": "{\n  \"a\": 1,\n  \"b\": oops\n}"}'
response
{
  "tool": "json-validator",
  "result": "{\n  \"valid\": false,\n  \"error\": \"Unexpected token 'o', ...\\\"1,\\n  \\\"b\\\": oops\\n}\\\" is not valid JSON\",\n  \"line\": 3,\n  \"column\": 8\n}",
  "chars": 130,
  "ms": 1
}

In your language

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

Why does a failure come back as 200 and not an error?
"Is this valid" is a question with two normal answers. The endpoint returns a report with "valid": false, so your script can branch on it. HTTP errors are reserved for problems with the request itself.
How accurate is the line and column?
It is exact. Node and Chrome stopped putting an offset in their JSON error messages, so the position is found by bisecting the document against the same error rather than parsing the message.
Does it check a schema?
No. This checks syntax and reports the shape it found: type, key count or item count, and size. Schema validation is a different job and belongs to a library in your own stack.

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