REST API v1

API Documentation

Format, minify, and validate JSON programmatically with the JsonBrain API. Requires a Pro subscription.

Get your API key from the editor — click the API Key button in the top navigation after signing in with a Pro account.

Authentication

All API requests require a Pro subscription and a valid API key. Pass your key in the X-API-Key request header.

Shell
curl -H "X-API-Key: jb_your_key_here" \
     -H "Content-Type: application/json" \
     -X POST https://api.jsonbrain.com/v1/format \
     -d '{"hello": "world"}'

Base URL

HTTPS https://api.jsonbrain.com/v1

All requests must be made over HTTPS. HTTP requests will be rejected.


POST /v1/format

Format (pretty-print) a JSON string. Returns the JSON formatted with configurable indentation and optional key sorting.

Request

Parameter Type Description
Content-Type header string application/json
body required string Raw JSON string to format (max 5MB)
indent query, optional integer Indentation spaces (1–8, default: 2)
sort_keys query, optional boolean Sort object keys alphabetically (default: false)

Example Request

cURL
curl -X POST 'https://api.jsonbrain.com/v1/format?sort_keys=true' \
  -H 'X-API-Key: jb_your_key_here' \
  -H 'Content-Type: application/json' \
  -d '{"b":2,"a":1}'

Example Response 200 OK

JSON
{
  "a": 1,
  "b": 2
}
POST /v1/minify

Minify a JSON string — strips all whitespace to produce the smallest valid JSON representation.

Request

Parameter Type Description
body required string Raw JSON string to minify (max 5MB)

Example Request

cURL
curl -X POST https://api.jsonbrain.com/v1/minify \
  -H 'X-API-Key: jb_your_key_here' \
  -H 'Content-Type: application/json' \
  -d '{ "name": "JsonBrain", "version": 1 }'

Example Response 200 OK

JSON
{"name":"JsonBrain","version":1}
POST /v1/validate

Validate JSON syntax. Returns whether the JSON is valid, any parse error message, and the size of the input in bytes.

Request

Parameter Type Description
body required string String to validate as JSON

Example Request

cURL
curl -X POST https://api.jsonbrain.com/v1/validate \
  -H 'X-API-Key: jb_your_key_here' \
  -H 'Content-Type: application/json' \
  -d '{"valid": true}'

Valid JSON Response 200 OK

JSON
{
  "valid": true,
  "error": null,
  "size_bytes": 15
}

Invalid JSON Response 200 OK

JSON
{
  "valid": false,
  "error": "Syntax error",
  "size_bytes": 7
}

Error Codes

All errors return a JSON body with an error field describing the issue.

Status Meaning
401

Unauthorized

Missing or invalid API key

403

Forbidden

Pro subscription required

413

Payload Too Large

Input exceeds the 5MB size limit

422

Unprocessable Entity

Invalid JSON — could not be parsed

429

Too Many Requests

Rate limit exceeded: 60 requests per minute per IP

502

Bad Gateway

Upstream processing error

Rate Limits

60 requests / minute

Limits are applied per IP address. If you exceed the limit, you'll receive a 429 Too Many Requests response. The limit resets every 60 seconds.


SDK Examples

Use any HTTP client. Here are examples using the most common languages.

$ cURL

Shell
# Format JSON
curl -X POST 'https://api.jsonbrain.com/v1/format?indent=4' \
  -H 'X-API-Key: jb_your_key_here' \
  -H 'Content-Type: application/json' \
  -d @your-file.json

# Validate JSON
curl -X POST https://api.jsonbrain.com/v1/validate \
  -H 'X-API-Key: jb_your_key_here' \
  -H 'Content-Type: application/json' \
  -d @your-file.json

JS JavaScript (fetch)

JavaScript
const formatJson = async (json) => {
  const response = await fetch('https://api.jsonbrain.com/v1/format', {
    method: 'POST',
    headers: {
      'X-API-Key': 'jb_your_key_here',
      'Content-Type': 'application/json',
    },
    body: JSON.stringify(json),
  });

  if (!response.ok) {
    throw new Error(`API error: ${response.status}`);
  }

  return response.text();
};

// Usage
const formatted = await formatJson({ name: 'JsonBrain', version: 1 });
console.log(formatted);

Py Python (requests)

Python
import requests

API_KEY = "jb_your_key_here"
BASE_URL = "https://api.jsonbrain.com/v1"
HEADERS = {"X-API-Key": API_KEY}

# Format JSON
def format_json(data, indent=2, sort_keys=False):
    response = requests.post(
        f"{BASE_URL}/format",
        headers=HEADERS,
        json=data,
        params={"indent": indent, "sort_keys": str(sort_keys).lower()},
    )
    response.raise_for_status()
    return response.text

# Validate JSON
def validate_json(data):
    response = requests.post(
        f"{BASE_URL}/validate",
        headers=HEADERS,
        json=data,
    )
    response.raise_for_status()
    return response.json()

# Usage
print(format_json({"name": "JsonBrain", "version": 1}))
print(validate_json({"hello": "world"}))