json-schemify
Converts any JSON structure to a valid JSON Schema object.
Getting started
Installation
npm install json-schemify --save-dev
Usage
const { schemify } = require('json-schemify');
or
import { schemify } from 'json-schemify';
API
The package exposes a single method:
schemify(json, options)
const schema = schemify(json, options);
Params
json
Any valid JSON.
options
Options object (all options are optional).
Option | Description |
---|
id | The $id property of the schema |
title | The title property of the schema |
Returns
A valid JSON Schema Object (draft-07)
Basic Example
This example returns a schema at the most basic level:
API
const { schemify } = require('json-schemify');
const json = {
firstName: 'John',
lastName: 'Doe',
age: 21,
};
const schema = schemify(json);
console.log(schema);
Result
{
$schema: "http://json-schema.org/draft-07/schema#",
type: "object",
properties: {
firstName: { "type": "string" },
lastName: { "type": "string" },
age: { "type": "integer" }
}
}