json-schema-it

json-schema-it

NPM

NPM version build codecov

JSON Schema generator.

import { generateSchema } from 'json-schema-it';

generateSchema(42); // { type: 'integer' }

NPM:

npm install json-schema-it

Yarn:

yarn add json-schema-it

ES Modules:

import { generateSchema } from 'json-schema-it';

CommonJS:

const { generateSchema } = require('json-schema-it');

Generate JSON Schema:

generateSchema({
productId: 1,
productName: 'A green door',
price: 12.5,
tags: ['home', 'green'],
});

Output:

{
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:

generateSchema(undefined); // Uncaught TypeError: Invalid JSON value: undefined

Release is automated with Release Please.

MIT