json-schema-it
v1.2.11
Published
JSON Schema generator.
Downloads
146
Maintainers
Readme
json-schema-it
JSON Schema generator.
Quick Start
import { generateSchema } from 'json-schema-it';
generateSchema(42); // { type: 'integer' }
Installation
NPM:
npm install json-schema-it
Yarn:
yarn add json-schema-it
Usage
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
Release is automated with Release Please.