Skip to content

Instantly share code, notes, and snippets.

@arttuladhar
Created May 2, 2017 21:00
Show Gist options
  • Save arttuladhar/56ac510d08219256edb15e38537c5e32 to your computer and use it in GitHub Desktop.
Save arttuladhar/56ac510d08219256edb15e38537c5e32 to your computer and use it in GitHub Desktop.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment