API Documentation

Integrate JSON formatting and AI features into your applications with our REST APIs and JavaScript SDK. Complete documentation with code examples.

Developer API & SDK Reference

Integrate FormatJSONOnline into your projects with our REST API, JavaScript SDK, and CLI tools.

REST API

For any HTTP client

JavaScript SDK

Built for Node.js & browsers

CLI Tools

Command-line usage

1. Authentication

API Key Authentication

All API requests require authentication with an API key passed in the Authorization header:

Authorization: Bearer sk_live_YOUR_API_KEY_HERE

Getting Your API Key

  1. Visit our Contact page
  2. Request API access
  3. Verify your email
  4. Access API dashboard to generate keys

2. REST API Endpoints

POST /api/v1/ai/generate

Generate mock JSON from a schema

Request Example (cURL)

curl -X POST https://api.formatjsononline.com/api/v1/ai/generate \ -H "Authorization: Bearer sk_live_YOUR_KEY" \ -H "Content-Type: application/json" \ -d '{ "schema": { "type": "object", "properties": { "id": { "type": "string" }, "email": { "type": "string" }, "age": { "type": "integer" } } }, "count": 5, "model": "gpt-4" }'

Response Example

{ "success": true, "data": [ { "id": "usr_001", "email": "alice@example.com", "age": 28 }, { "id": "usr_002", "email": "bob@example.com", "age": 35 }, ... ], "requestId": "req_abc123", "timestamp": "2026-03-03T10:30:00Z" }

POST /api/v1/ai/fix

Auto-fix invalid or malformed JSON

Request Example (JavaScript)

const response = await fetch('https://api.formatjsononline.com/api/v1/ai/fix', { method: 'POST', headers: { 'Authorization': 'Bearer sk_live_YOUR_KEY', 'Content-Type': 'application/json' }, body: JSON.stringify({ malformedJSON: "{name: 'John', age: 30}", model: "claude-3-sonnet" }) }); const result = await response.json(); console.log(result.data.fixed);

Response Example

{ "success": true, "data": { "fixed": { "name": "John", "age": 30 }, "original": "{name: 'John', age: 30}", "explanation": "Added double quotes around keys and values", "confidence": 0.97 } }

POST /api/v1/validate

Validate JSON syntax and structure

curl -X POST https://api.formatjsononline.com/api/v1/validate \ -H "Authorization: Bearer sk_live_YOUR_KEY" \ -H "Content-Type: application/json" \ -d '{ "json": "{\"name\": \"John\", \"age\": 30}" }' // Response { "valid": true, "errors": [], "warnings": [] }

3. JavaScript SDK

Installation

npm install @formatjsononline/sdk # or with yarn yarn add @formatjsononline/sdk # or with pnpm pnpm add @formatjsononline/sdk

Basic Usage

import { FormatJSON } from '@formatjsononline/sdk'; // Initialize client const client = new FormatJSON({ apiKey: 'sk_live_YOUR_API_KEY' }); // Format JSON const formatted = await client.format(jsonString, { indent: 2, sortKeys: true }); console.log(formatted); // Validate JSON const validation = await client.validate(jsonString); if (validation.valid) { console.log('✓ Valid JSON'); } else { console.error('✗ Errors:', validation.errors); } // Generate mock data const mockData = await client.ai.generate({ schema: { type: 'object', properties: { name: { type: 'string' }, email: { type: 'string' } } }, count: 10 }); console.log(mockData);

Advanced: Batch Processing

// Process multiple files const files = [file1, file2, file3]; const results = await Promise.all( files.map(file => client.format(file, { indent: 2 })) ); // Filter valid JSON const validResults = await Promise.all( files.map(async (file) => ({ file, validation: await client.validate(file) })) ).then(results => results.filter(r => r.validation.valid).map(r => r.file) );</code> </div> </div> </div> </section> {/* CLI Tools */} <section> <h2 className="text-2xl font-bold text-blue-600 mb-6">4. Command-Line Interface</h2> <div className="space-y-6"> <div className="border rounded-lg p-6"> <h3 className="font-semibold mb-3">Installation</h3> <div className="bg-gray-100 dark:bg-gray-900 rounded p-4 font-mono text-xs overflow-x-auto"> <code>{CLI_INSTALL_CMD} export FJSON_API_KEY=sk_live_YOUR_KEY # Or use .env file echo "FJSON_API_KEY=sk_live_YOUR_KEY" > ~/.fjson_env

Usage Examples

Format a file

fjson format input.json --output output.json --indent 2 --sort

Validate JSON

fjson validate data.json # Output: # ✓ Valid JSON # - 245 keys # - 12 arrays # - Max depth: 5

Convert formats

fjson convert config.xml --to json --output config.json fjson convert data.json --to csv --output data.csv fjson convert data.json --to yaml --output data.yaml

Generate mock data

fjson ai:generate --schema schema.json --count 100 --output mock.json

5. Python Client (Coming Soon)

A comprehensive Python client library is in development. Expected release: Q2 2026.

# Preview (planned API) from formatjson import FormatJSON client = FormatJSON(api_key='sk_live_YOUR_KEY') # Format JSON formatted = client.format(json_data, indent=2, sort_keys=True) # Validate validation = client.validate(json_data) if validation['valid']: print("✓ Valid JSON") # Generate mock data mock_data = client.ai.generate( schema={...}, count=100 )

Contact us to be notified when Python SDK is available.

6. Error Handling

Standard Error Responses

400 Bad Request

{ "error": true, "code": "INVALID_PAYLOAD", "message": "Schema must be an object" }

401 Unauthorized

{ "error": true, "code": "UNAUTHORIZED", "message": "Invalid or missing API key" }

429 Rate Limited

{ "error": true, "code": "RATE_LIMIT_EXCEEDED", "message": "Too many requests", "retryAfter": 60 }

Handling Errors (JavaScript)

try { const result = await client.ai.generate({ schema: {...} }); } catch (error) { if (error.code === 'RATE_LIMIT_EXCEEDED') { // Exponential backoff await delay(error.retryAfter * 1000); return retry(); } else if (error.code === 'UNAUTHORIZED') { console.error('Check your API key'); } else { console.error('Unexpected error:', error.message); } }

7. Rate Limits & Quotas

PlanRequests/MinMax PayloadCost
Free5/min (unauthenticated)5 MBFree
Pro60/min100 MB$9/month
EnterpriseUnlimited1 GBCustom

Rate Limit Headers

Every response includes:

X-RateLimit-Limit: 60
X-RateLimit-Remaining: 45
X-RateLimit-Reset: 1678879800

Support & Resources