mirror of
https://github.com/metafy-social/python-scripts.git
synced 2024-11-23 20:11:10 +00:00
Check JSON format python scripts
This commit is contained in:
parent
9fc3a69b1e
commit
f368c2987e
10
scripts/Check_json_format/README.md
Normal file
10
scripts/Check_json_format/README.md
Normal file
|
@ -0,0 +1,10 @@
|
|||
# 1 checkjson
|
||||
|
||||
This script will read a file and either pass the file as being a valid JSON file,
|
||||
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.
|
||||
|
||||
## to RUN it
|
||||
|
||||
$ checkjson test.json
|
||||
|
||||
That’s all you need to validate JSON, but it can easily be modified to validate YAML, as well.
|
14
scripts/Check_json_format/script.py
Normal file
14
scripts/Check_json_format/script.py
Normal file
|
@ -0,0 +1,14 @@
|
|||
import os
|
||||
import sys
|
||||
import json
|
||||
|
||||
if len(sys.argv) > 1:
|
||||
if os.path.exists(sys.argv[1]):
|
||||
file = open(sys.argv[1], "r")
|
||||
json.load(file)
|
||||
file.close()
|
||||
print("Validate JSON!")
|
||||
else:
|
||||
print(sys.argv[1] + " not found")
|
||||
else:
|
||||
print("Usage: checkjson.py <file>")
|
Loading…
Reference in New Issue
Block a user