Skip to content

Instantly share code, notes, and snippets.

@mr-rizwan-syed
Last active December 2, 2023 06:32
Show Gist options
  • Save mr-rizwan-syed/5403ad815897a64ee57533c02cd62dfe to your computer and use it in GitHub Desktop.
Save mr-rizwan-syed/5403ad815897a64ee57533c02cd62dfe to your computer and use it in GitHub Desktop.
Python code for converting naabu json file to CSV
import argparse
import json
import csv
# Define command-line arguments
parser = argparse.ArgumentParser(description="Convert JSON to CSV")
parser.add_argument("input_file", help="Input Naabu JSON file path")
parser.add_argument("output_file", help="Output CSV file path")
args = parser.parse_args()
# Open the input JSON file for reading
with open(args.input_file, 'r') as json_file:
data = json_file.readlines()
# Open the output CSV file for writing
with open(args.output_file, 'w', newline='') as csv_file:
csv_writer = csv.writer(csv_file)
# Write the CSV header based on your desired fields
csv_writer.writerow(['host', 'ip', 'port', 'protocol', 'tls', 'timestamp'])
# Iterate over each JSON object in the file
for line in data:
item = json.loads(line)
csv_writer.writerow([item['host'], item['ip'], item['port'], item['protocol'], item['tls'], item['timestamp']])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment