spark: add json-check.py - validate and pretty-print JSON files or stdin
This commit is contained in:
1 parent
b14d2e42cb
commit
233007b0c5
1 file changed
+17
Executable
+17
@@ -0,0 +1,17 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""json-check: Validate and pretty-print JSON files or stdin."""
|
||||||
|
import json
|
||||||
|
import sys
|
||||||
|
|
||||||
|
def main():
|
||||||
|
if len(sys.argv) > 1:
|
||||||
|
with open(sys.argv[1], 'r') as f:
|
||||||
|
data = json.load(f)
|
||||||
|
else:
|
||||||
|
data = json.load(sys.stdin)
|
||||||
|
|
||||||
|
print(json.dumps(data, indent=2, sort_keys=True))
|
||||||
|
return 0
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
sys.exit(main())
|
||||||
Reference in new issue
Block a user