Python Forum
How can i parse a log file to JSON. - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: How can i parse a log file to JSON. (/thread-27092.html)



How can i parse a log file to JSON. - menarcarlos - May-25-2020

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.


RE: How can i parse a log file to JSON. - pyzyx3qwerty - May-26-2020

https://stackoverflow.com/questions/35220002/log-file-to-json-file-conversion/35221057


RE: How can i parse a log file to JSON. - buran - May-26-2020

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