Converts any JSON structure to a valid JSON Schema object.
npm install json-schemify --save-dev
const { writeSchema } = require('json-schemify');
writeSchema(json
, filepath
, options
)
Writes to a JSON schema output file.
const json= {
firstName: 'John',
lastName: 'Doe',
age: 21,
}
writeSchema(json, 'schema.json');
Any valid JSON.
The filepath of the file to write.
Option | Description |
---|---|
id? | The $id property of the schema |
title? | The title property of the schema |
prettyPrint? | Pretty print Json output |
schemify(json
, options
)
Returns the JSON schema object (rather than writing to file).
const json= {
firstName: 'John',
lastName: 'Doe',
age: 21,
}
const schema = schemify(json);
// do something with schema
console.log(schema);
Any valid JSON.
Option | Description |
---|---|
id? | The $id property of the schema |
title? | The title property of the schema |
A valid JSON Schema Object (draft-07)
This example returns a basic schema.
{
firstName: 'John',
lastName: 'Doe',
age: 21,
};
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"firstName": { "type": "string" },
"lastName": { "type": "string" },
"age": { "type": "integer" }
}
}