Skip to content

Instantly share code, notes, and snippets.

@safebuffer
Last active March 14, 2023 03:36
Show Gist options
  • Save safebuffer/68b27f254208f873863fa67db0dceefe to your computer and use it in GitHub Desktop.
Save safebuffer/68b27f254208f873863fa67db0dceefe to your computer and use it in GitHub Desktop.
Nmap XML output to Json
import json,xmltodict
"""
Nmap XML Output to Json Output in Python
example : data = xml2json('nmap_output.xml')
"""
def xml2json(xml):
xmlfile = open(xml)
xml_content = xmlfile.read()
xmlfile.close()
xmljson = json.dumps(xmltodict.parse(xml_content), indent=4, sort_keys=True)
jsondata = json.loads(xmljson)
return jsondata
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment