JSON Schema for TypeScript
This package provides:
- JSON schema types for TypeScript (in namespace
t
) - a builder for building JSON schema (in namespace
s
) - infer the type given the JSON schema built by the builder (with
t.TSType<T>
)
Examples
import {s, t} from 'json-schema-ts';
const sex = s.string<'male' | 'female'>({'enum': ['male', 'female']});
const personSchema = s.object({
'title': 'person',
'description': 'Person information',
'definitions': {
'sex': sex,
},
'properties': {
'name': s.string(),
'fullName': s.tuple({'items': s.items(s.string(), s.string())}),
'age': s.number(),
'friends': s.array({'items': s.string()}),
'sex': s.ref('#/definitions/sex', sex),
}
});
type IPerson = t.TSType<typeof personSchema>;
License
MIT. See LICENSE.