JSON Schema generator

Generate a JSON Schema from example JSON. Arrays of objects are merged into one item shape.

Input

Example JSON to describe.
Spaces per level. 0 gives one compact line.

Result

Fill in the input and press Run.

Your input is processed in memory and then discarded. It is not stored or logged. Even so, don't paste live passwords or keys into any online tool.

Use it from code or an agent

curl -s https://setget.net/v1/tools/json-schema-infer \
  -H 'Content-Type: application/json' \
  -d '{"input":{"text":"[{\"id\":1,\"name\":\"a\"},{\"id\":2}]","indent":0}}'
import json, urllib.request

body = {'input': {'text': '[{"id":1,"name":"a"},{"id":2}]', 'indent': 0}}
request = urllib.request.Request("https://setget.net/v1/tools/json-schema-infer", json.dumps(body).encode(),
                                 {"Content-Type": "application/json"})
print(json.load(urllib.request.urlopen(request))["result"])
const response = await fetch("https://setget.net/v1/tools/json-schema-infer", {
  method: "POST",
  headers: {"Content-Type": "application/json"},
  body: JSON.stringify({"input":{"text":"[{\"id\":1,\"name\":\"a\"},{\"id\":2}]","indent":0}}),
});
console.log((await response.json()).result);
Tool: run_tool
Arguments:
{
  "slug": "json-schema-infer",
  "input": {
    "text": "[{\"id\":1,\"name\":\"a\"},{\"id\":2}]",
    "indent": 0
  }
}
{
  "input": {
    "text": "[{\"id\":1,\"name\":\"a\"},{\"id\":2}]",
    "indent": 0
  }
}

Endpoint: POST /v1/tools/json-schema-infer. Over MCP: run_tool with slug: "json-schema-infer". Machine-readable: input schema, Markdown. Connect an agent.

Inputs

NameTypeRequiredWhat it does
text string yes Example JSON to describe.
indent integer no Spaces per level. 0 gives one compact line. Default: 2. From 0 to 8.

Example

Input
{
  "text": "[{\"id\":1,\"name\":\"a\"},{\"id\":2}]",
  "indent": 0
}
Result
{
  "text": "{\"$schema\":\"https://json-schema.org/draft/2020-12/schema\",\"type\":\"array\",\"items\":{\"type\":\"object\",\"properties\":{\"id\":{\"type\":\"integer\"},\"name\":{\"type\":\"string\"}},\"required\":[\"id\"]}}"
}

Questions

How is "required" decided?
A key is required only if it appears in every example object.