Skip to content

Commit

Permalink
Merge pull request #100 from wmetcalf/FixUpFirstJsonScopeHandling
Browse files Browse the repository at this point in the history
Fix for invalid JSON output (variable scoping), when we specify multiple rule files, and have hits from multiple rule files.
  • Loading branch information
wagga40 authored Feb 4, 2025
2 parents 4d75b5c + c5bc142 commit a1c535b
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions zircolite.py
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,7 @@ def __init__(
self.timeField = timeField
self.hashes = hashes
self.delimiter = delimiter

self.first_json_output = True # To manage commas in JSON output
def close(self):
self.dbConnection.close()

Expand Down Expand Up @@ -1106,7 +1106,6 @@ def executeRuleset(
Execute all rules in the ruleset and handle output.
"""
csvWriter = None
first_json_output = True # To manage commas in JSON output
is_json_mode = not self.csvMode

# Prepare output file handle if needed
Expand Down Expand Up @@ -1188,10 +1187,10 @@ def executeRuleset(
# Write results as JSON using orjson
try:
# Handle commas between JSON objects
if not first_json_output:
if not self.first_json_output:
fileHandle.write(",\n")
else:
first_json_output = False
self.first_json_output = False
# Serialize ruleResults to JSON bytes with indentation
json_bytes = json.dumps(
ruleResults, option=json.OPT_INDENT_2
Expand Down

0 comments on commit a1c535b

Please sign in to comment.