https://github.com/braze-community/json-schema-it
📝 JSON Schema generator.
https://github.com/braze-community/json-schema-it
json json-schema json-schema-generator npm schema typescript
Last synced: about 2 months ago
JSON representation
📝 JSON Schema generator.
- Host: GitHub
- URL: https://github.com/braze-community/json-schema-it
- Owner: braze-community
- License: mit
- Created: 2023-08-18T02:44:29.000Z (almost 2 years ago)
- Default Branch: master
- Last Pushed: 2024-10-29T19:31:13.000Z (7 months ago)
- Last Synced: 2024-10-29T21:36:43.404Z (7 months ago)
- Topics: json, json-schema, json-schema-generator, npm, schema, typescript
- Language: TypeScript
- Homepage: https://braze-community.github.io/json-schema-it/
- Size: 2.05 MB
- Stars: 1
- Watchers: 0
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# json-schema-it
[](https://nodei.co/npm/json-schema-it/)
[](https://www.npmjs.com/package/json-schema-it)
[](https://github.com/braze-community/json-schema-it/actions/workflows/build.yml)
[](https://codecov.io/gh/braze-community/json-schema-it)[JSON Schema](https://json-schema.org/) generator.
## Quick Start
```ts
import { generateSchema } from 'json-schema-it';generateSchema(42); // { type: 'integer' }
```## Installation
[NPM](https://www.npmjs.com/package/json-schema-it):
```sh
npm install json-schema-it
```[Yarn](https://yarnpkg.com/package/json-schema-it):
```sh
yarn add json-schema-it
```## Usage
ES Modules:
```ts
import { generateSchema } from 'json-schema-it';
```CommonJS:
```ts
const { generateSchema } = require('json-schema-it');
```Generate JSON Schema:
```ts
generateSchema({
productId: 1,
productName: 'A green door',
price: 12.5,
tags: ['home', 'green'],
});
```Output:
```ts
{
type: 'object',
properties: {
productId: { type: 'integer' },
productName: { type: 'string' },
price: { type: 'number' },
tags: { type: 'array', items: { type: 'string' } },
},
}
```An error will be thrown for an invalid JSON value:
```ts
generateSchema(undefined); // Uncaught TypeError: Invalid JSON value: undefined
```## Release
Release is automated with [Release Please](https://github.com/googleapis/release-please).
## License
[MIT](https://github.com/braze-community/json-schema-it/blob/master/LICENSE)