Transform JSON data object to relational form (sql or csv)
This package allows you to transform valid json object to relational form. The output of the application can be in a form of one .sql
file with create table
statements or a set of .csv
files, with file names corresponding to table names.
Using npm:
npm install --global json-to-rel
or using yarn:
yarn global add json-to-rel
Run the scipt using the command line
json-to-rel -i input-file.json -m sql -o output-dir/
Setting | Description | Short flag | Full flag | Values |
---|---|---|---|---|
Input file | Path to a file with input JSON object | -i | --input | path/to/file.json |
Output directory | Path to a directory in which the application will store files with the results of the processing | -o | --output | path/to/direcory/ |
Mode | Type of data and files that will be generated | -m | --mode | sql | csv |
Logging | Activating optional logging to a file with log’s level of detail (the higher the value, the more detailed the log messages) | -l | --logging | 0 | 1 | 2 |
Configuration file | Path to file with additional configuration JSON object | -c | --config | path/to/file.json |
-
SQL
A
.sql
file with a set ofcreate table
statements representing relational tables mapped from json object. Each table featutes a surrogate primary key. Tables are connected with foreign key constraints. Syntax is compliant withSqlite 3
. -
CSV
A set of
.csv
files with file names corresponding to table names. Each file contains a header with table column names and rows which correspond to table records with values from input json object.
You can pass your own configuration file, which will override default configuration. Your configuration file can look like this.
{
"inputFileEncoding": "utf8",
"outputFileName": "tables.sql",
"rootTableName": "GENERATED",
"surrogatePrimaryKeyName": "__ID",
"logFile": "json2rel.log",
"csvDelimiters": {
"col": ";",
"row": "\n"
},
"generatedAttributeName": "value",
"truncateTableName": false
}
You can find detailed information using help.
json-to-rel --help
Feel free to fork this github repository to find ways to improve this package.
-
Install dependencies
npm install
-
Run script
npm start
If you want to pass arguments to the script please use the following command with full parameter flags like so:
npm start -- --input /path/to/input --mode sql --output /path/to/output
- Simulate package installation with
npm link
. - Run the program with
json-to-rel
command followed by arguments. - Remove package with
npm unlink
.