arttuladhar
5/2/2017 - 9:00 PM

Checks Valid JSON in a directory

Checks Valid JSON in a directory

#!/bin/python

import os
import json

script_dir = '.'

valid_json = 0
invalid_json = 0

for root, dirs, files in os.walk(script_dir):
    for file in files:
      if file.endswith(".json"):
        with open(file) as f:
          try:
            out = json.load(f)
            print "Valid JSON ", file
            valid_json = valid_json + 1
          except:
            print "Invalid JSON ", file
            invalid_json = invalid_json + 1
            pass

print "Valid JSON - ", valid_json
print "Invalid JSON - ", invalid_json