Python Forum
How can i parse a log file to JSON.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How can i parse a log file to JSON.
#1
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.
Reply
#2
https://stackoverflow.com/questions/3522...n/35221057
pyzyx3qwerty
"The greatest glory in living lies not in never falling, but in rising every time we fall." - Nelson Mandela
Need help on the forum? Visit help @ python forum
For learning more and more about python, visit Python docs
Reply
#3
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
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  encrypt data in json file help jacksfrustration 1 185 Mar-28-2024, 05:16 PM
Last Post: deanhystad
  parse json field from csv file lebossejames 4 722 Nov-14-2023, 11:34 PM
Last Post: snippsat
  parse/read from file seperated by dots giovanne 5 1,088 Jun-26-2023, 12:26 PM
Last Post: DeaD_EyE
  Python Script to convert Json to CSV file chvsnarayana 8 2,487 Apr-26-2023, 10:31 PM
Last Post: DeaD_EyE
  Loop through json file and reset values [SOLVED] AlphaInc 2 2,076 Apr-06-2023, 11:15 AM
Last Post: AlphaInc
  [split] Parse Nested JSON String in Python mmm07 4 1,515 Mar-28-2023, 06:07 PM
Last Post: snippsat
  Converting a json file to a dataframe with rows and columns eyavuz21 13 4,368 Jan-29-2023, 03:59 PM
Last Post: eyavuz21
  validate large json file with millions of records in batches herobpv 3 1,254 Dec-10-2022, 10:36 PM
Last Post: bowlofred
  Writing to json file ebolisa 1 993 Jul-17-2022, 04:51 PM
Last Post: deanhystad
  Trying to parse only 3 key values from json file cubangt 8 3,438 Jul-16-2022, 02:05 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020