Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f368c29

Browse files
committed
Check JSON format python scripts
1 parent 9fc3a69 commit f368c29

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# 1 checkjson
2+
3+
This script will read a file and either pass the file as being a valid JSON file,
4+
or die a horrible death. But for all practical reasons, it tells me if the error is in the file or the program that I am trying to load the file into.
5+
6+
## to RUN it
7+
8+
$ checkjson test.json
9+
10+
That’s all you need to validate JSON, but it can easily be modified to validate YAML, as well.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import os
2+
import sys
3+
import json
4+
5+
if len(sys.argv) > 1:
6+
if os.path.exists(sys.argv[1]):
7+
file = open(sys.argv[1], "r")
8+
json.load(file)
9+
file.close()
10+
print("Validate JSON!")
11+
else:
12+
print(sys.argv[1] + " not found")
13+
else:
14+
print("Usage: checkjson.py <file>")

0 commit comments

Comments
 (0)