📚 Documentation

Everything you need to integrate JSON Guardian

← Back to Home

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:

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

MethodEndpointDescription
GET/healthHealth check (returns OK)
POST/api/v1/validateValidate JSON against schema
POST/api/v1/repairRepair malformed JSON
POST/api/v1/enforceValidate + repair combined
POST/api/v1/batchBatch validation
POST/api/v1/keysCreate new API key
GET/api/v1/usageCheck 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.

Keep your API key secret! Don't expose it in client-side code or public repositories.

Validation Endpoint

POST /api/v1/validate

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

POST /api/v1/repair

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

Enforce Endpoint

POST /api/v1/enforce

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

StatusMeaning
200Success
400Bad request (invalid JSON or schema)
401Unauthorized (missing or invalid API key)
429Rate limited (too many requests)
500Server 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"
  }'
Need help? Email support@jsonguardian.com — we respond within 24 hours.