I have the below log file in the following format. I need to convert the log file into json file using python. How can it be made?
[2015-07-13 00:03:05,976] hostna
Import pythons json library:
import json
Read in the file as a string and get everything after the 'Response:' substring:
with open("logfile", "r") as log_file:
log_string = log_file.read()
response_string = log_string.split("Response:")[1].strip()
Get a python object from response_string
:
response_obj = json.loads(response_string)
If you need to, write that object out to a file after doing whatever you need with it:
with open("outfile", "w") as out_file:
out_file.write(json.dumps(response_obj))