Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

98
Views
Analizar un archivo de registro en un objeto json

Tengo un archivo de registro llamado request.log , este es el contenido del archivo de registro

 [2022-06-30T09:56:40.146Z] ### POST https://test.csdf/auth/send_otp { "method": "POST", "headers": { "User-Agent": "testing", "Content-Type": "application/json" } } [2022-06-30T09:56:40.668Z] ### POST https://test.csdf/auth/login { "method": "POST", "headers": { "User-Agent": "testing", "Content-Type": "application/json" } }

¿Cómo puedo analizar el archivo de registro y transformarlo en un objeto json de matriz como este?

 [ { "method": "POST", "url": "https://test.co/otp" }, { "method": "POST", "url": "https://test.co/login" } ]
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Tienes que ejecutar algún tipo de script para convertirlos a JSON. En javascript/nodejs podrías hacer algo como esto:

 const logFileContents = `[2022-06-30T09:56:40.146Z] ### POST https://test.csdf/auth/send_otp { "method": "POST", "headers": { "User-Agent": "testing", "Content-Type": "application/json" } } [2022-06-30T09:56:40.668Z] ### POST https://test.csdf/auth/login { "method": "POST", "headers": { "User-Agent": "testing", "Content-Type": "application/json" } }`; function convertToJSON(logs) { return logs .match(/\[.+\]\s\#+\s\w+\s.*\n/g) // fetch lines to parse .map((line) => line.split('###')[1].trim().split(' ')) //isolate method/url .map((log) => ({ method: log[0], url: log[1], }));// convert array to object } console.log(JSON.stringify(convertToJSON(logFileContents), null, 4));

si no funciona para sus archivos de registro, simplemente corrija la expresión regular para que coincida con su caso

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!