xtract.bot

JSON to JSON Schema

Try it interactively →
POST /api/json-to-jsonschema

Generate a JSON Schema (Draft 2020-12) from sample JSON. Infers types, required fields, and array element shapes. Useful for typing APIs from real responses.

Inspects example JSON values and emits a JSON Schema (Draft 2020-12) that would validate them. Handy for: - Generating an initial schema from a real-world API response to use as documentation or validation seed. - Building TypeScript types from sample data (the schema is the input to most TS-from-schema generators). - Diffing two API responses by schema rather than value. Pass an array of values to infer from multiple examples — the tool computes the union shape (a field is `required` only when present in every example).

Inputs

NameTypeDefaultDescription
samples*stringJSON array of sample documents. Pass `[doc]` for a single sample, `[doc1, doc2,.]` to union multiple shapes.
noRequiredbooleanfalseEmit no `required` arrays — every property becomes optional. Use when samples are sparse.

Response

Modes: json. Cache: yes (24h TTL).

Code samples

Built from the user-shape example.


curl -X POST https://api.xtract.bot/api/json-to-jsonschema \
  -H "Content-Type: application/json" \
  -H "Accept: application/json" \
  -H "X-Account-Id: $XTRACT_ACCOUNT_ID" \
  -H "X-Api-Key: $XTRACT_API_KEY" \
  -d '{
  "samples": "[{\"id\":1,\"name\":\"Ada\",\"email\":\"ada@example.com\"},{\"id\":2,\"name\":\"Grace\"}]",
  "noRequired": false
}'