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 | |
parent | 6eb49bfaac55b7d77531d7a923fbdd013263d2bb (diff) | |
download | dexon-tests-4b886515543e15b316f219f5c16db1e6e661dff0.tar dexon-tests-4b886515543e15b316f219f5c16db1e6e661dff0.tar.gz dexon-tests-4b886515543e15b316f219f5c16db1e6e661dff0.tar.bz2 dexon-tests-4b886515543e15b316f219f5c16db1e6e661dff0.tar.lz dexon-tests-4b886515543e15b316f219f5c16db1e6e661dff0.tar.xz dexon-tests-4b886515543e15b316f219f5c16db1e6e661dff0.tar.zst dexon-tests-4b886515543e15b316f219f5c16db1e6e661dff0.zip |
Check for duplicate keys in JSON objects
-rw-r--r-- | .travis.yml | 2 | ||||
-rwxr-xr-x | JSONSchema/validate.js | 9 |
2 files changed, 7 insertions, 4 deletions
diff --git a/.travis.yml b/.travis.yml index f3d378022..db91ed687 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,7 +8,7 @@ branches: - master - develop sudo: false -install: "npm install jsonschema" +install: "npm install jsonschema json-duplicate-key-handle" script: # won't fail, but print problems - find . -name "*.json" -not -name "*Filler.json" -exec echo {} \; -exec python -mjson.tool {} /dev/null \; 2>&1 | grep -v -B 1 "^\./" | cat 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); |