alkira/validate-json.py

29 lines
676 B
Python
Executable File

#!/usr/bin/env python3
import sys
import json
import argparse
# Parse all arguments
parser = argparse.ArgumentParser(description="Push JSON connfig to AlkirAPI")
parser.add_argument("-f", "--file", type=str, help="location of the JSON connector file")
parser.add_argument("-p", "--pretty", help="make the JSON pretty!", action="store_true")
if len(sys.argv)==1:
parser.print_help(sys.stderr)
sys.exit(1)
try:
args = parser.parse_args()
json_file = args.file
except argparse.ArgumentError as e:
print(str(e))
sys.exit()
with open (json_file, 'r') as f:
body = json.load(f)
if args.pretty:
print(json.dumps(body, indent=4))
else:
print(json.dumps(body))