Effortlessly convert your NDJSON data to a JSON Schema.
- Powered by:
generate-schema
$ npm install --save ndjson-generate-schema
# Or to use the CLI globally
$ npm install --global ndjson-generate-schema
Given an NDJSON file dogs.db
:
{"id":1,"name":"Buddy","breed":"Boston Terrier"}
{"id":2,"name":"Charley"}
$ 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
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"
}
}
*/
}
);
-
Required
:String
the title of the Schema
-
Required
:String
the NDJSON file to read
ISC © Buster Collings