https://github.com/redocly/json-to-json-schema
Convert JSON examples into JSON schema (supports Swagger 2, OpenAPI 3 and 3.1)
https://github.com/redocly/json-to-json-schema
json-schema openapi openapi3 swagger
Last synced: 6 months ago
JSON representation
Convert JSON examples into JSON schema (supports Swagger 2, OpenAPI 3 and 3.1)
- Host: GitHub
- URL: https://github.com/redocly/json-to-json-schema
- Owner: Redocly
- Created: 2022-03-16T05:21:04.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2024-07-09T12:53:52.000Z (over 1 year ago)
- Last Synced: 2025-06-26T11:26:15.564Z (6 months ago)
- Topics: json-schema, openapi, openapi3, swagger
- Language: TypeScript
- Homepage: https://redocly.com/tools/json-to-json-schema
- Size: 183 KB
- Stars: 28
- Watchers: 14
- Forks: 5
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# json-to-json-schema
[](https://www.npmjs.com/package/@redocly/json-to-json-schema) [](https://bundlephobia.com/package/@redocly/json-to-json-schema) [](https://bundlephobia.com/package/@redocly/json-to-json-schema) [](https://coveralls.io/github/Redocly/json-to-json-schema?branch=main)
Convert JSON examples into JSON schema.
Supports JSON Schema `draft-05` used in Swagger 2.0 and OpenAPI 3.0 and new draft `draft-2020-12` used in OpenAPI 3.1.
## Usage
```js
import { convert, format } from '@redocly/json-to-json-schema';
const example = { firstname: 'John', surname: 'Doe', birthday: '1990-02-23' };
const schema = convert(example, {
target: 'draft-05-oas', // or draft-2020-12
includeExamples: false,
disableAdditionalProperties: false,
inferRequired: false,
});
```
Output:
```yaml
firstname:
type: string
surname:
type: string
birthday:
type: string
format: date
```
## Similar tools
https://github.com/mohsen1/json-to-json-schema