-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathvalidate-json.sh
More file actions
executable file
·33 lines (29 loc) · 969 Bytes
/
Copy pathvalidate-json.sh
File metadata and controls
executable file
·33 lines (29 loc) · 969 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
#!/usr/bin/env bash
set -euo pipefail
LOG="/tmp/e2e-output.log"
python3 -c "
import json, sys
# The JSON output may be prefixed with a logger timestamp (e.g. '2026-04-08 22:46:50,580: {...}').
# Try parsing the full line first, then from the first '{' character.
found = False
with open('$LOG') as f:
for line in f:
line = line.strip()
if not line or '{' not in line:
continue
# Try full line first, then from the first brace
for candidate in (line, line[line.index('{'):]):
try:
data = json.loads(candidate)
if isinstance(data, dict):
found = True
print(f'PASS: Valid JSON output with {len(data)} top-level key(s)')
break
except json.JSONDecodeError:
continue
if found:
break
if not found:
print('FAIL: No valid JSON object found in output')
sys.exit(1)
"