Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

json-schemify

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json-schemify

Parses any JSON to a valid JSON Schema object.

  • 0.0.9
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
41
decreased by-18%
Maintainers
1
Weekly downloads
 
Created
Source

json-schemify

json-schemify

Converts any JSON structure to a valid JSON Schema object.

npm

Build Status

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

OptionDescription
idThe $id property of the schema
titleThe 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:

JSON

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

API

const schema = generate(json, {
  id: 'https://example.com/person.schema.json',
  title: 'Person',
});

console.log(schema);

Result

{
  $id: "https://example.com/person.schema.json",
  $schema: "http://json-schema.org/draft-07/schema#",
  title: "Person",
  type: "object",
  properties: {
    firstName: { "type": "string" },
    lastName: { "type": "string" },
    age: { "type": "integer" }
  }
}

Writing to file?

If the JSON schema is required to be written to file jsonfile does the job very well.

Keywords

FAQs

Package last updated on 17 Nov 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc