Skip to content

Commit fa0c55a

Browse files
authored
Merge pull request Rishi098#53 from dimpeshmalviya/main
Create json_formatter.py
2 parents 2be857e + c0a7711 commit fa0c55a

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

json_formatter.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# filename: json_formatter.py
2+
# Run: python json_formatter.py '{"name":"Ravi","age":22}'
3+
4+
import json, sys
5+
6+
if len(sys.argv) != 2:
7+
print("Usage: python json_formatter.py '<json_string>'")
8+
sys.exit(1)
9+
10+
try:
11+
obj = json.loads(sys.argv[1])
12+
print(json.dumps(obj, indent=4, sort_keys=True))
13+
except json.JSONDecodeError as e:
14+
print("Invalid JSON:", e)

0 commit comments

Comments
 (0)