A utility application to converts database tables to JSON Schema files.
The current implementation will generate JSON Schema which complies with the Draft 4 specification
The following requirement have been defined:
The application should take a JDBC URL and a table name as the input.
All input arguments should be set via the CLI
The application should generate a valid JSON schema.
All output should be written to STDOUT
If a database column is defined as NOT NULL, it will appear in the JSON schema under the required key.
If the database column has a default value, it will be used to set the default property in the JSON schema.
The database column type will be used to define the JSON schema data type using the following mapping:
| Database | JSON Schema |
|---|---|
| integer | integer |
| decimal | number |
| string | string |
| any | string |
The database column length will be used, for certain data types, to define constraints in the JSON schema.
| Database | Constraint |
|---|---|
| string | maxLength |
| integer | maximum |
| integer | minimum |
| decimal | maximum |
| decimal | minimum |
| datetime | format |
If the database provides column comment features, and these values are provided, then populate the description property of the JSON schema.
Read one or more rows from the database table and set the examples property in the JSON schema.
The examples property is defined at the column level and can hold one or more entries.
Build the project
./mvnw packageThe artifacts built by this project are located in the target/dist directory.
To install the program, copy this directory and its contents to any machine with Java 11+ installed.
cd dist/bin
java -cp "./*;../lib/*" consulting.cloudpro.jdbc2js.Application jdbc:oracle:thin:@//localhost:1521/ORCLPDB1 lss changeme LSS/ENT_ORDER_CINSWe cannot use -jar and cp at the same time for java command. Instead, we include the application JAR in the classpath and call the main class manually.
This application does not contain any drivers for connectivity to a database.
You must locate and download a relevant database driver and copy to the lib directory in the application installation directory.
The type of driver required by JDBC is based upon the JDBC URL that is supplied when running the program.
To ensure database drivers are kept separate from the main application libraries, and each other, it is recommended is to create a new directory, per database version, in the main installation lib directory e.g. <installation-path>/lib/oracle-12g and copy all the necessary driver JAR files into that directory. You can then include the driver directory in the classpath argument to ensure the drivers are available to the application at runtime.
java -cp "./*;../lib/*;../lib/oracle-12g/*" ...