Create API Documentation from JSON
Generate TypeScript types, OpenAPI specs, and mock endpoints from a single JSON payload to accelerate frontend development.
Last updated:
When building APIs, you often start with a sample JSON response and need to generate all the supporting artifacts โ type definitions, OpenAPI schemas, mock endpoints, and documentation. DataLensia lets you derive all of these from a single JSON payload.
๐ฉ The Scenario
You're designing a new /api/products endpoint and have a sample response:
[
{
"id": "prod_001",
"name": "Wireless Headphones",
"price": 79.99,
"inStock": true,
"categories": ["electronics", "audio"],
"specs": {
"battery_hours": 30,
"bluetooth_version": "5.3",
"weight_grams": 250
}
}
]
๐ ๏ธ Step 1: Generate TypeScript Types
- Open the JSON Convert tool.
- Paste your sample JSON.
- Select TypeScript from the format grid.
- Copy the generated types:
interface Specs {
battery_hours: number;
bluetooth_version: string;
weight_grams: number;
}
interface Product {
id: string;
name: string;
price: number;
inStock: boolean;
categories: string[];
specs: Specs;
}
type RootType = Product[];
๐ ๏ธ Step 2: Generate JSON Schema
- Open the Schema Generator.
- Paste the same JSON.
- Copy the generated JSON Schema (Draft 2020-12) for request/response validation.
๐ ๏ธ Step 3: Generate OpenAPI Spec
- Open the JSON Convert tool.
- Select OpenAPI from the API/Schema category.
- The tool generates an OpenAPI 3.0 specification with schemas derived from your data.
๐ ๏ธ Step 4: Create a Mock Endpoint
- Open the Mock API Generator.
- Paste your sample JSON.
- Configure: Status
200, MethodGET, Delay200ms. - Click Generate Link.
- Use the generated URL in your frontend while the backend is being built:
const res = await fetch("https://datalensia.com/api/mock/m1.eJy...");
const products = await res.json();
๐ ๏ธ Step 5: Add Dynamic Values
Make your mock more realistic with Faker.js placeholders:
[
{
"id": "{{faker.string.uuid()}}",
"name": "{{faker.commerce.productName()}}",
"price": "{{faker.commerce.price()}}",
"inStock": true,
"categories": ["{{faker.commerce.department()}}"]
}
]
Every request to your mock endpoint now returns different, realistic data.
๐ก Complete Workflow Summary
| Step | Tool | Output |
|---|---|---|
| 1 | Convert โ TypeScript | .ts type definitions |
| 2 | Schema Generator | JSON Schema (Draft 2020-12) |
| 3 | Convert โ OpenAPI | OpenAPI 3.0 YAML |
| 4 | Mock API Generator | Live REST endpoint |
| 5 | Mock + Faker | Dynamic mock data |
๐ฏ Benefits
- Single source of truth: One JSON sample generates all artifacts.
- Frontend unblocked: Developers can code against mock endpoints immediately.
- Consistent contracts: TypeScript types and JSON Schema ensure frontend and backend agree on the data shape.
- Zero infrastructure: Everything runs locally in the browser, no deployment needed.
๐ Try it now
Start with any JSON in the Convert Tool, generate TypeScript types, then create a mock endpoint in the Mock API Generator.