Skip to content

Commit 2028852

Browse files
committed
output formatted json
Tool: gitpod/catfood.gitpod.cloud
1 parent dc85aac commit 2028852

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

trivy_scanner.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,15 +117,15 @@ while IFS= read -r image || [ -n "$image" ]; do
117117
if echo "$trivy_output" | jq empty > /dev/null 2>&1; then
118118
# Direct approach - create the combined JSON object using jq directly
119119
jq -c --arg image "$image" --arg scan_time "$scan_time" \
120-
'. + {image: $image, scan_time: $scan_time}' <<< "$trivy_output" >> "$OUTPUT_FILE"
120+
'. + {image: $image, scan_time: $scan_time}' <<< "$trivy_output" | jq >> "$OUTPUT_FILE"
121121
else
122122
# If trivy output is not valid JSON, treat as error
123123
echo "Warning: Trivy returned invalid JSON for $image"
124124
jq -n --arg image "$image" \
125125
--arg scan_time "$scan_time" \
126126
--arg error "Invalid JSON output from Trivy" \
127127
--arg details "$trivy_output" \
128-
'{image: $image, scan_time: $scan_time, error: $error, error_details: $details}' >> "$OUTPUT_FILE"
128+
'{image: $image, scan_time: $scan_time, error: $error, error_details: $details}' | jq >> "$OUTPUT_FILE"
129129
fi
130130
else
131131
# For error cases, create a simple JSON object

0 commit comments

Comments
 (0)