'command line application in node for searching key value in json .log file

I am using only yargs and not GREP for this and trying to implement simple commands as -v to return an object in which the value match or -k to return an object in which the key match and I am returning this in the terminal itself using the console.log.

So, the problem is that the data is in even JSON .log file and I can't just parse it so I was converting it into an array first and then using it for the actual searching. Is there a way for searching an uneven array for key/value if found then return that JSON object using Yargs?

The JSON .log file type

{"request": "/forumData", "verb": "GET", "host": "codesnip.com", "request_id": "dc9be12fca2e9065799109ca97cb14a7", "port": 8088, "app": "iOS:2.22.14", "event": "res-json", "time": 0.946825095, "level": "info", "message": "", "timestamp": "Thu Oct "}
{"request": "/api/v2/tmUpdates/", "verb": "GET", "host": "codesnip.me", "request_id": "215be9f0ee1b76856ecc5fa8dbe50302", "port": 8021, "event": "start-request", "level": "info", "message": "", "timestamp": "Thu Oct 14 2021"}
{"event": "hiring", "destination": "codesnip", "skills": "Python, Javascript", "contact": "911123382590"}
{"request": "/api/v2/tmUpdates/", "verb": "GET", "host": "codesnip.me", "request_id": "215be9f0ee1b76856ecc5fa8dbe50302", "port": 8088, "event": "async-task", "time": 9.75, "task": "restrictingGroupPermissions", "level": "info", "message": "", "timestamp": "Thu Oct 14 2022"}
{"since": "2021-10-14T07:32:00.723Z", "request": "/api/v2/tmUpdates/", "verb": "GET", "host": "codesnip.com", "request_id": "215be9f0ee1b76856ecc5fa8dbe50302", "port": 8088, "event": "sync-request", "level": "info", "message": "", "timestamp": "Thu Oct 14 2021"}
{"request": "/login", "verb": "GET", "host": "codesnip.com", "request_id": "1cdda501b2dc6043491df3181b0f3e08", "port": 8099, "event": "complete-request", "time": 0.009173137, "response": 200, "start_time": "Thu Oct 14 2022", "level": "info", "message": "", "timestamp": "Thu Oct 14 2022"}

and I am converting it into an array by

const read = new Promise((resolve, reject) => {
    fs.readFile('json_sample.log', (err,data) => {
        var temp = JSON.parse(JSON.stringify(data.toString()))
        while(temp.trim().length > 0){
         var trim = temp.substring(temp.indexOf("{"), temp.indexOf("}") + 1)
          temp = temp.replace(trim, "")
          arr.push(JSON.parse(trim))
        }
        console.log(arr)
        resolve(arr)
    })
})

read.then((e) => console.log(e))


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source