Table of Contents
Overview
JSON Guardian is a high-performance REST API that solves a critical problem in AI applications: LLMs frequently produce malformed or schema-violating JSON, causing production failures. This service provides:
- Validation – Verify JSON against schemas (JSON Schema Draft 7)
- Repair – Automatically fix common JSON syntax errors
- Enforcement – Combined validation + repair in one call
Base URL: https://api.jsonguardian.com
Quick Start
1. Health check
curl https://api.jsonguardian.com/health
# Output: OK
2. Validate JSON
curl -X POST https://api.jsonguardian.com/api/v1/validate \
-H "Content-Type: application/json" \
-H "X-API-Key: your-api-key" \
-d '{
"schema": {
"type": "object",
"properties": {
"name": {"type": "string"},
"age": {"type": "number"}
},
"required": ["name", "age"]
},
"data": "{\"name\": \"John\", \"age\": 30}"
}'
3. Repair broken JSON
curl -X POST https://api.jsonguardian.com/api/v1/repair \
-H "Content-Type: application/json" \
-H "X-API-Key: your-api-key" \
-d '{"data": "{\"name\": \"John\", \"age\": 30,}"}'
API Endpoints
| Method | Endpoint | Description |
|---|---|---|
| GET | /health | Health check (returns OK) |
| POST | /api/v1/validate | Validate JSON against schema |
| POST | /api/v1/repair | Repair malformed JSON |
| POST | /api/v1/enforce | Validate + repair combined |
| POST | /api/v1/batch | Batch validation |
| POST | /api/v1/keys | Create new API key |
| GET | /api/v1/usage | Check usage statistics |
Authentication
All API calls (except /health) require an API key in the header:
X-API-Key: your-api-key
Get your API key from the dashboard after signing up.
Validation Endpoint
Request body
{
"schema": {
"type": "object",
"properties": {
"name": {"type": "string"},
"age": {"type": "number"}
},
"required": ["name", "age"]
},
"data": "{\"name\": \"John\", \"age\": 30}"
}
Response (success)
{
"valid": true,
"errors": [],
"parsed_data": {
"name": "John",
"age": 30
}
}
Response (validation error)
{
"valid": false,
"errors": [
{
"path": "/age",
"message": "\"thirty\" is not of type \"number\""
}
],
"parsed_data": null
}
Repair Endpoint
Request body
{
"data": "{\"name\": \"John\", \"age\": 30,}"
}
Notice the trailing comma, which is invalid JSON.
Response
{
"success": true,
"original": "{\"name\": \"John\", \"age\": 30,}",
"repaired": "{\n \"name\": \"John\",\n \"age\": 30\n}",
"repaired_data": {
"name": "John",
"age": 30
}
}
What gets repaired
- Trailing commas:
{"a": 1,}→{"a": 1} - Missing closing braces
- Single quotes:
{'a': 'b'}→{"a": "b"} - Unquoted keys:
{name: "John"}→{"name": "John"} - Escape sequence issues
Enforce Endpoint
Combines repair and validation in one call. First repairs the JSON, then validates against the schema.
{
"schema": {
"type": "object",
"properties": {
"name": {"type": "string"}
}
},
"data": "{\"name\": \"John\",}"
}
Error Handling
| Status | Meaning |
|---|---|
200 | Success |
400 | Bad request (invalid JSON or schema) |
401 | Unauthorized (missing or invalid API key) |
429 | Rate limited (too many requests) |
500 | Server error |
Code Examples
Choose your language. More languages can be added here without changing the page layout.
async function validateJSON(schema, data) {
const response = await fetch('https://api.jsonguardian.com/api/v1/validate', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-API-Key': 'your-api-key'
},
body: JSON.stringify({ schema, data })
});
return await response.json();
}
const schema = {
type: "object",
properties: {
name: { type: "string" },
age: { type: "number" }
},
required: ["name", "age"]
};
const result = await validateJSON(schema, '{"name": "John", "age": 30}');
if (result.valid) {
console.log("Valid JSON:", result.parsed_data);
} else {
console.log("Validation errors:", result.errors);
}
import requests
class JSONGuardian:
def __init__(self, api_key):
self.api_key = api_key
self.base_url = "https://api.jsonguardian.com/api/v1"
def validate(self, schema, data):
response = requests.post(
f"{self.base_url}/validate",
headers={
"Content-Type": "application/json",
"X-API-Key": self.api_key
},
json={"schema": schema, "data": data}
)
return response.json()
def repair(self, data):
response = requests.post(
f"{self.base_url}/repair",
headers={
"Content-Type": "application/json",
"X-API-Key": self.api_key
},
json={"data": data}
)
return response.json()
# Usage
client = JSONGuardian("your-api-key")
schema = {
"type": "object",
"properties": {
"name": {"type": "string"},
"age": {"type": "number"}
},
"required": ["name", "age"]
}
result = client.validate(schema, '{"name": "John", "age": 30}')
if result["valid"]:
print("Valid:", result["parsed_data"])
else:
print("Errors:", result["errors"])
# Validate
curl -X POST https://api.jsonguardian.com/api/v1/validate \
-H "Content-Type: application/json" \
-H "X-API-Key: your-api-key" \
-d '{
"schema": {
"type": "object",
"properties": {
"name": {"type": "string"},
"age": {"type": "number"}
},
"required": ["name", "age"]
},
"data": "{\"name\": \"John\", \"age\": 30}"
}'
# Repair
curl -X POST https://api.jsonguardian.com/api/v1/repair \
-H "Content-Type: application/json" \
-H "X-API-Key: your-api-key" \
-d '{"data": "{\"name\": \"John\", \"age\": 30,}"}'
API key tiers
Available tiers: free (10k/mo), starter (100k/mo), pro (1M/mo). Create keys from your dashboard or via the API.
curl -X POST https://api.jsonguardian.com/api/v1/keys \
-H "Content-Type: application/json" \
-H "X-API-Key: your-api-key" \
-d '{
"name": "My Production Key",
"tier": "pro"
}'