A validator and storage library using the JSON table schema written in PHP.
This is a great utility library for validating that CSV files, streams or any other data source validates against a predefined JSON table schema definition.
Although this library has many great features, it does not (yet) adhere to the entire JSON table schema specification.
Currently the parts of the specification that are NOT supported are:
- binary (this is just validated as a string)
Constraints currently there is no support for constraints.
- To meet our specific needs this has been built to reference a database table and not a data package as outlined in the specification.
The same schema structure is accepted but with the following considerations: * "datapackage" MUST be "postgresql". * "resource" MUST be the name of the table to use with optional schema qualifier. I.E. "import.t_table_name". * "fields" follow the JSON table schema specification but refer to the fields in the database table.
It is used to validate and store data as part of a import tool for users of Halo.
We use a lot of open source projects at Footwork Solutions and this project, along with our other open source work is our way of giving back to the community we appreciate so much.
See the examples directory for a detailed run through of how to validate and store a CSV file.
Validate a CSV file:
// Instantiate the analysis class. $lo_analyser = new \JsonTable\Analyse(); // Let the analyser know where the JSON table schema is. $lo_analyser->set_schema('/your/file/path/example.json'); // Let the analyser know where the CSV file to validate is. $lo_analyser->set_file('/your/file/path/example.csv'); // Check whether the file is valid against the schema. $lb_file_is_valid = $lo_analyser->validate();
Store the valid CSV file:
$lo_store = \JsonTable\Store::load('postgresql'); $lb_file_is_stored = $lo_store->store('your_table_name');
composer require footwork_solutions/json_table
- datetime; date; time - fmt:[PATTERN] - This supports PHP date formats @see http://php.net/manual/en/datetime.formats.date.php
- datetime; date; time - ISO8610 - The following formats are validated without specifing a format:
- Combined date and time in UTC: 2015-03-09T13:07:04Z
- Date: 2015-03-09
- Time: hh:mm:ss
- Given the range of options that match the ISO8610 format, we recommend that you always specify a format.
- Pattens: A delimiter must be included in the regex.
- Column name checking is case insensitive.
- Foreign keys with a single field can be omitted from the CSV and the foreign key check will be ignored. However, foreign keys with multiple fields must have all those fields in the CSV file.
Bugs & Feature Requests
Please use the issue tracker to report any bugs or request new features.
Pull Requests are always welcome.
- Fork the repository.
- Create your feature branch (git checkout -b my-new-feature).
- Commit your changes.
- Push to the branch (git push origin my-new-feature).
- Create a new Pull Request.
This is free software distributed under the terms of the MIT license. See LICENCE for the full details.