diff options
author | Yoichi Hirai <i@yoichihirai.com> | 2018-03-19 21:52:48 +0800 |
---|---|---|
committer | Yoichi Hirai <i@yoichihirai.com> | 2018-03-19 22:03:04 +0800 |
commit | 4b886515543e15b316f219f5c16db1e6e661dff0 (patch) | |
tree | 48197e1cb7e024ba319105a26e3c1f5e759c9d81 /JSONSchema/validate.js | |
parent | 6eb49bfaac55b7d77531d7a923fbdd013263d2bb (diff) | |
download | tangerine-tests-4b886515543e15b316f219f5c16db1e6e661dff0.tar tangerine-tests-4b886515543e15b316f219f5c16db1e6e661dff0.tar.gz tangerine-tests-4b886515543e15b316f219f5c16db1e6e661dff0.tar.bz2 tangerine-tests-4b886515543e15b316f219f5c16db1e6e661dff0.tar.lz tangerine-tests-4b886515543e15b316f219f5c16db1e6e661dff0.tar.xz tangerine-tests-4b886515543e15b316f219f5c16db1e6e661dff0.tar.zst tangerine-tests-4b886515543e15b316f219f5c16db1e6e661dff0.zip |
Check for duplicate keys in JSON objects
Diffstat (limited to 'JSONSchema/validate.js')
-rwxr-xr-x | JSONSchema/validate.js | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/JSONSchema/validate.js b/JSONSchema/validate.js index 9206f961c..4e4e1fde0 100755 --- a/JSONSchema/validate.js +++ b/JSONSchema/validate.js @@ -4,6 +4,7 @@ var fs = require('fs'); var validate = require('jsonschema').validate; var readline = require('readline'); var process = require('process'); +var dup = require('json-duplicate-key-handle'); var schemaFile = process.argv[2]; @@ -29,8 +30,9 @@ rl.on('line', function(fileName) { }); rl.on('close', function() { - schema = JSON.parse(fs.readFileSync(schemaFile)); - + var jsonString = fs.readFileSync(schemaFile, "utf8"); + schema = dup.parse(jsonString); + //sort file names alphabetically so that log output ordering is consistent fileNames.sort(function(a,b) { if(a<b) { @@ -44,7 +46,8 @@ rl.on('close', function() { for (var i = 0; i < fileNames.length; i++) { try { - testCode = JSON.parse(fs.readFileSync(fileNames[i])); + var jsonString = fs.readFileSync(fileNames[i], "utf8"); + testCode = dup.parse(jsonString); } catch(e) { console.log('error on file:', fileNames[i]) console.log(e); |