-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgroq.py
More file actions
43 lines (36 loc) · 983 Bytes
/
groq.py
File metadata and controls
43 lines (36 loc) · 983 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
input_str = '{"a":"b","e":{"f":"g"},"c":"d"}'
output_str = ""
last_found = 0
while True:
last_found = input_str.find('{', last_found)
if last_found == -1:
break
output_str += " {\n"
last_found += 1
current_level = 1
i = last_found + 1
while True:
i += 1
if input_str[i] == '{':
current_level += 1
elif input_str[i] == '}':
current_level -= 1
if current_level == 0:
output_str += " }\n"
break
elif input_str[i] == ',':
output_str += ",\n"
else:
if current_level > 1:
output_str += " \""
else:
output_str += " \""
while True:
i += 1
if input_str[i] == '"':
break
output_str += input_str[i]
output_str += "\"\n"
last_found = i
output_str += "}"
print(output_str)