How to use the JSON to OpenAPI Schema
Generate OpenAPI schemas from JSON:
1
Paste your JSON response
Paste a JSON object representing a typical API response. Arrays of objects are also accepted — the first element is used for schema inference.
2
Set schema name
Enter the component schema name in PascalCase (e.g. UserResponse, ProductList). Nested objects automatically generate their own named schemas with $ref references.
3
Choose output format
Select YAML (the OpenAPI community standard) or JSON. Both outputs are OpenAPI 3.0 compatible and drop into any spec file.
4
Paste into your OpenAPI file
Copy the output under components/schemas/ in your openapi.yaml or openapi.json. Reference schemas in path responses using $ref: '#/components/schemas/YourSchema'.
When to use this tool
Use this when documenting REST APIs with OpenAPI:
- →Adding response schemas to an OpenAPI spec from real API response JSON
- →Bootstrapping an openapi.yaml file from existing API endpoint responses
- →Documenting a third-party API for internal use by generating schemas from its responses
- →Creating Swagger UI or Redoc documentation from JSON request/response examples
- →Generating component schemas for use with Stoplight, Postman, or API Gateway integrations
Frequently asked questions
Q:Is the output OpenAPI 3.0 or Swagger 2.0?
The tool generates OpenAPI 3.0 syntax under components/schemas, which is the current standard used by Swagger UI 3+, Redoc, and Stoplight. Swagger 2.0 used definitions instead of components/schemas — if you need Swagger 2.0, move the schema content under definitions and remove the nullable keyword.
Q:What format annotations are auto-detected?
The generator detects and applies OpenAPI format values automatically: email fields get format: email, URL/URI fields get format: uri, 24-char hex strings get format: uuid, ISO datetime strings get format: date-time, date-only strings get format: date, and password/secret fields get format: password with a masked example value.
Q:How are nested objects handled?
Nested JSON objects generate separate named schemas and are referenced using $ref: '#/components/schemas/NestedName'. Nested schemas appear before the root schema in the output so the $ref order is correct for all OpenAPI tooling. Arrays of objects generate a named schema and use items: $ref.
Q:Can I use this with Swagger UI?
Yes — paste the generated schemas under components/schemas in your openapi.yaml file. In your path definitions, reference them with $ref: '#/components/schemas/YourSchema' inside response content blocks. The output is fully compatible with Swagger UI, Redoc, and Stoplight Studio.
Q:How is the required array determined?
Fields whose values are not null in the sample JSON are added to the required array. Fields with null values are marked nullable: true and excluded from required. Review and adjust both after generating — a single JSON sample may not reflect which fields are truly optional in your API contract.
Q:Can I export as both YAML and JSON?
Yes — use the YAML/JSON toggle in the toolbar to switch output formats. Both are OpenAPI 3.0 compatible. YAML is recommended for human-edited spec files; JSON is useful for programmatic processing or APIs that consume OpenAPI specs as JSON (like AWS API Gateway).