1.0.0 • Published 3 years ago

json-schemify v1.0.0

Weekly downloads
1
License
MIT
Repository
github
Last release
3 years ago

json-schemify

json-schemify

Converts any JSON structure to a valid JSON Schema object.

npm CI

Getting started

Installation

npm install json-schemify --save-dev

Usage

const { writeSchema } = require('json-schemify');

API

writeSchema

writeSchema(json, filepath, options)

Writes to a JSON schema output file.

const json= {
  firstName: 'John',
  lastName: 'Doe',
  age: 21,
}

writeSchema(json, 'schema.json');

Params

json

Any valid JSON.

filepath

The filepath of the file to write.

options
OptionDescription
id?The \$id property of the schema
title?The title property of the schema
prettyPrint?Pretty print Json output

schemify

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);

Params

json

Any valid JSON.

options
OptionDescription
id?The \$id property of the schema
title?The title property of the schema

Returns

A valid JSON Schema Object (draft-07)

Example

This example returns a basic schema.

Json

{
  firstName: 'John',
  lastName: 'Doe',
  age: 21,
};

Result

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "properties": {
    "firstName": { "type": "string" },
    "lastName": { "type": "string" },
    "age": { "type": "integer" }
  }
}
1.0.0

3 years ago

0.0.11

3 years ago

0.0.12

3 years ago

0.0.13

3 years ago

0.0.10

5 years ago

0.0.9

5 years ago

0.0.8

5 years ago

0.0.7

5 years ago

0.0.6

5 years ago

0.0.5

6 years ago

0.0.4

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago

0.0.0

6 years ago