aboutsummaryrefslogtreecommitdiffstats
path: root/JSONSchema/validate.js
diff options
context:
space:
mode:
Diffstat (limited to 'JSONSchema/validate.js')
-rwxr-xr-xJSONSchema/validate.js50
1 files changed, 50 insertions, 0 deletions
diff --git a/JSONSchema/validate.js b/JSONSchema/validate.js
new file mode 100755
index 000000000..368d28da2
--- /dev/null
+++ b/JSONSchema/validate.js
@@ -0,0 +1,50 @@
+#! /bin/env node
+
+var validate = require('jsonschema').validate;
+var fs = require('fs');
+
+var readline = require('readline');
+var schema = '';
+var testCode = '';
+
+var readline = require('readline');
+var rl = readline.createInterface({
+ input: process.stdin,
+ output: process.stdout,
+ terminal: false
+});
+
+rl.on('line', function(line){
+ fs.readFile('schema.json', function(err, data) {
+ if (err) {
+ throw err;
+ }
+
+ schema = JSON.parse(data);
+
+ fs.readFile(line, function(err, data) {
+ if (err) {
+ throw err;
+ }
+
+ try {
+ testCode = JSON.parse(data);
+ } catch(e) {
+ console.log(e);
+ }
+
+ try {
+ var x = validate(testCode, schema);
+
+ if (x.errors.length > 0) {
+ console.log(line+':\n');
+ for (var i = 0; i < x.errors.length; i++) {
+ console.log(' '+x.errors[i]+'\n')
+ }
+ }
+ } catch(e) {
+ console.log(e);
+ }
+ });
+ });
+});