Code Utilities 3 credits COMPUTE

JSON to TypeScript API

Generate TypeScript interface definitions from JSON example data via REST API. Infers types from values, handles nested objects (generates nested interfaces), handles arrays (infers element types), and handles optional fields across multiple example objects.

Try it live →

How it works

POST a JSON object or array. The API inspects the structure and value types, generates appropriate TypeScript interface names from context, handles null as T | null, and returns a complete .ts compatible interface definition.

Use cases

API Reference

POST https://slopshop.gg/v1/code-json-to-typescript
Authorization: Bearer YOUR_API_KEY
Content-Type: application/json

Input parameters

ParameterTypeRequiredDescription
input string | object required The input data to process

Example response

{
  "data": {
    "result": "success",
    "processed": true
  },
  "meta": {
    "credits_used": 3,
    "engine": "real",
    "ms": 4
  }
}

Examples

Three real-world scenarios showing how developers use JSON to TypeScript in production.

Example 1
Type an API response
Generate a TypeScript interface from a real API response object.
curl -X POST https://slopshop.gg/v1/code-json-to-typescript \
  -H "Authorization: Bearer $SLOPSHOP_KEY" \
  -H "Content-Type: application/json" \
  -d '{"json": {"id": 42, "name": "Alice", "email": "alice@example.com", "created_at": "2025-01-15T10:30:00Z", "plan": {"type": "pro", "expires": "2026-01-15"}}}'
Example 2
Type a config file
Generate TypeScript types for a JSON configuration structure.
curl -X POST https://slopshop.gg/v1/code-json-to-typescript \
  -H "Authorization: Bearer $SLOPSHOP_KEY" \
  -H "Content-Type: application/json" \
  -d '{"json": {"server": {"port": 3000, "host": "localhost"}, "database": {"url": "postgres://...", "pool": 10}, "features": {"enableBeta": false}}}'
Example 3
Type an event payload
Create a TypeScript interface for a webhook event payload.
curl -X POST https://slopshop.gg/v1/code-json-to-typescript \
  -H "Authorization: Bearer $SLOPSHOP_KEY" \
  -H "Content-Type: application/json" \
  -d '{"json": {"event": "order.created", "order_id": 1234, "customer": {"id": 99, "email": "bob@example.com"}, "total": 149.99, "items": [{"sku": "ABC", "qty": 2}]}}'

Code examples

curl

curl -X POST https://slopshop.gg/v1/code-json-to-typescript \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"input": "your data here"}'

Python

import requests

response = requests.post(
    "https://slopshop.gg/v1/code-json-to-typescript",
    headers={"Authorization": "Bearer YOUR_API_KEY"},
    json={"input": "your data here"}
)
result = response.json()
print(result["data"])

Node.js

const response = await fetch("https://slopshop.gg/v1/code-json-to-typescript", {
  method: "POST",
  headers: {
    "Authorization": "Bearer YOUR_API_KEY",
    "Content-Type": "application/json"
  },
  body: JSON.stringify({ input: "your data here" })
});
const { data } = await response.json();
console.log(data);

CLI

# Install the Slopshop CLI
npm install -g slopshop

# Set your API key
export SLOPSHOP_KEY=your_api_key

# Call code-json-to-typescript
slop code-json-to-typescript '{"input": "your data here"}'

Pricing

Credits per call
3
credits
Cost per call
$0.003
at Starter tier
Tier
COMPUTE
Pure compute

Credits are purchased in bundles starting at $1 for 1,000 credits. All compute APIs like this one use 3 credits per call — that's $0.003. See all pricing tiers.

Related APIs in Code Utilities

View the full API catalog · Try in playground · Documentation