Skip to content

ℹ️ Effortlessly convert your NDJSON data to a JSON Schema.

License

Notifications You must be signed in to change notification settings

busterc/ndjson-generate-schema

Repository files navigation

ndjson-generate-schema NPM version Build Status Dependency Status Coverage percentage

Effortlessly convert your NDJSON data to a JSON Schema.

Installation

$ npm install --save ndjson-generate-schema

# Or to use the CLI globally
$ npm install --global ndjson-generate-schema

Usage

Given an NDJSON file dogs.db:

{"id":1,"name":"Buddy","breed":"Boston Terrier"}
{"id":2,"name":"Charley"}

CLI

$ ndjson-generate-schema

  Effortlessly convert your NDJSON data to a JSON Schema.

  Usage

    $ ndjson-generate-schema <title> <file> [outfile]

  Inputs

    title     Required, Title of Schema
    file      Required, NDJSON file to read
    outfile   Optional, filename to write Schema out to

Module

const path = require('path');
const ndjsonGenerateSchema = require('ndjson-generate-schema');

ndjsonGenerateSchema('Dogs', path.resolve(__dirname, 'dogs.db')).then(
  schema => {
    console.log(schema);
    /*
    {
      "$schema": "http://json-schema.org/draft-04/schema#",
      "title": "Dogs Set",
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "id": {
            "type": "number"
          },
          "name": {
            "type": "string"
          },
          "breed": {
            "type": "string"
          }
        },
        "required": [
          "id",
          "name"
        ],
        "title": "Dogs"
      }
    }
    */
  }
);

API

ndjsonGenerateSchema(title, file)

  • title

    • Required : String the title of the Schema
  • file

    • Required : String the NDJSON file to read

License

ISC © Buster Collings