From 4b886515543e15b316f219f5c16db1e6e661dff0 Mon Sep 17 00:00:00 2001 From: Yoichi Hirai Date: Mon, 19 Mar 2018 14:52:48 +0100 Subject: Check for duplicate keys in JSON objects --- .travis.yml | 2 +- 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