|
10 | 10 | ## Features |
11 | 11 |
|
12 | 12 | - Written in typescript |
13 | | -- Infers JSON Schema |
| 13 | +- Inspired by [jtd-infer](https://jsontypedef.com/docs/jtd-infer/) |
| 14 | +- Generate JSON schema documents from example data |
14 | 15 | - Supports most string formats through [json-infer-types](https://github.com/jsonhero-io/json-infer-types) |
15 | 16 | - Date and times |
16 | 17 | - URIs |
17 | 18 | - Email Addresses |
18 | 19 | - Hostnames |
19 | 20 | - IP Addresses |
20 | 21 | - uuids |
21 | | -- Infers JSON Type definitions |
22 | | -- Supports hints for discriminators (tagged unions), value-only schemas, and enums |
23 | | -- Provide with multiple JSON documents to improve inference |
| 22 | +- Available as a CLI and a library |
| 23 | +- Supports snapshotting and restoring inference sessions |
24 | 24 |
|
25 | 25 | ## Usage |
26 | 26 |
|
| 27 | +```ts |
| 28 | +import { inferSchema } from "@jsonhero/schema-infer"; |
| 29 | + |
| 30 | +inferSchema({ |
| 31 | + id: "abeb8b52-e960-44dc-9e09-57bb00d6b441", |
| 32 | + name: "Eric", |
| 33 | + emailAddress: "eric@example.com", |
| 34 | + website: "https://github.com/ericallam", |
| 35 | + joined: "2022-01-01", |
| 36 | +})toJSONSchema(); |
| 37 | +``` |
| 38 | + |
| 39 | +Infers the following JSON schema: |
| 40 | + |
| 41 | +```json |
| 42 | +{ |
| 43 | + "$schema": "https://json-schema.org/draft/2020-12/schema", |
| 44 | + "type": "object", |
| 45 | + "properties": { |
| 46 | + "id": { "type": "string", "format": "uuid" }, |
| 47 | + "name": { "type": "string" }, |
| 48 | + "emailAddress": { "type": "string", "format": "email" }, |
| 49 | + "website": { "type": "string", "format": "uri" }, |
| 50 | + "joined": { "type": "string", "format": "date" } |
| 51 | + }, |
| 52 | + "required": ["id", "name", "emailAddress", "website", "joined"] |
| 53 | +} |
| 54 | +``` |
| 55 | + |
| 56 | +## Examples |
| 57 | + |
27 | 58 | ## Roadmap |
28 | 59 |
|
| 60 | +- Add support for hints for discriminators (tagged unions), value-only schemas, and enums |
| 61 | +- Add support for [JSON Typedefs](https://jsontypedef.com) |
29 | 62 | - Add "verbose" mode to include `$id`, `examples`, etc. |
0 commit comments