Skip to content

Instantly share code, notes, and snippets.

@marksweiss
Created July 31, 2013 17:57
Show Gist options
  • Save marksweiss/6124432 to your computer and use it in GitHub Desktop.
Save marksweiss/6124432 to your computer and use it in GitHub Desktop.
Minimal Python script to validate JSON. Just uses standard library 'json' loads one ore files and catches and reports the first exception thrown in attempting to load and parse each file. Takes one argument a path to the files to validate. The script will glob* that path and attempt to load and parse as JSON all files found there.
#!/usr/bin/python
from glob import glob
import json
import sys
def main(path):
files = glob(path)
for file in files:
try:
json.load(open(file))
except ValueError as err:
print "file {0} failed validation. Error: {1}".format(file, err)
if __name__ == '__main__':
# Example Usage: ./validate_json.py ./path_to_files_to_validate/\*
main(sys.argv[1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment