File tree Expand file tree Collapse file tree 2 files changed +24
-0
lines changed
scripts/Check_json_format Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change
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.
Original file line number Diff line number Diff line change
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>" )
You can’t perform that action at this time.
0 commit comments