json-schema-it
TypeScript icon, indicating that this package has built-in type declarations

1.2.6 • Public • Published

json-schema-it

NPM

NPM version build codecov

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.

License

MIT

Package Sidebar

Install

npm i json-schema-it

Weekly Downloads

14

Version

1.2.6

License

MIT

Unpacked Size

25.3 kB

Total Files

35

Last publish

Collaborators

  • remarkablemark