Python Forum

Full Version: How can i parse a log file to JSON.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi, I'm noob in python.

How can i parse a log file to JSON.

From this:


Quote: -----------------------------------
Uncollected accounts
-----------------------------------
.
Date debut
16/04/20 22:41:22

PL/SQL procedure successfully completed.

Date end
16/04/20 22:41:39
.
-----------------------------------
Control figures
-----------------------------------
.
Date debut
16/04/20 22:41:23
Date fin
16/04/20 22:41:48
.
----------------------------
End of Daily Treatments
----------------------------
.
Date end
16/04/20 22:41:49


To this:


Quote: ['process', 'date debut', 'date end', 'hour start', 'hour end']

['Uncollected accounts', '16/04/20', '16/04/20', '22:41:22', '22:41:39']

and so on.

Many thanks.
the expected output you show is not JSON, show what you expect as output. It may be ndjson, but it uses single quotes
otherwise parse the log file and identify separate records - it looks easy task - either by reading and analyzing each line or using regex