LogViewPlus Support

Nested JSON Parser

https://www.logviewplus.com/forum/Topic2089.aspx

By ofir - 26 Feb 2024

Hi I collect logs from the client and I have general data on the session and the device and then I have the log entries.
The question is if there is any way of displaying the metadata (general data) of the JSON? because now it shows me only the log entries... 
This is JSON for example:
{
    "SessionData": {
        "UserId": "1",
        "SessionId": "d6d83d0081c1e1c3b5fcb6b04df685",
        "Username": "admin",
        "ServerURL": "url",
        "ApplicationVersion": "4.16.0",
        "IsOffline": "False",
        "StartSessionTime": "26/02/2024 08:23:49",
        "EndSessionTime": "26/02/2024 08:24:39"
    },
    "DeviceData": {
        "Platform": "Windows",
        "DeviceModel": "System Product Name (System manufacturer)",
        "OSVersion": "Windows 10 (10.0.19045) 64bit",
        "MemoryInfoMB": "31.93945",
        "AppFilesStorageMB": "800",
        "ScreenResolution": "(1230.0, 698.0)",
        "StartBatteryLevel": "-100",
        "EndBatteryLevel": "-100"
    },
    "Entries": [
        {
            "Type": "Internal",
            "Message": "The referenced script (EH_Comp) on this Behaviour is missing!",
            "StackTrace": "",
            "Time": "08:24:17"
        },
        {
            "Type": "Exception",
            "Message": "ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.\r\nParameter name: index",
            "StackTrace": "",
            "Time": "08:24:34"
        }
]
}
By LogViewPlus Support - 26 Feb 2024

Thanks for reaching out.  Log entries in a JSON array are tricky because we need to specify the root node as an array before defining the log structure.  This is not supported using the ParserWizard, so the configuration must be done manually.

I am able to get a good parse with:
{
  "Entries": [
   {
    "Type": "%c",
    "Message": "%m",
    "StackTrace": "%S{StackTrace}",
    "Time": "%d{%H:mm:ss}"
   }
]}



In the screenshot below, I have duplicated the second log entry.  Notice that the header is considered part of the first log entry:



Hope that helps,

Toby




  
By ofir - 26 Feb 2024

Yeah I know the first row contains this data, the question is if there is any way to display this data in another way, because it is not intuitive way to read this data.
By LogViewPlus Support - 26 Feb 2024

No.  The header data cannot be displayed in another way.  Log entries in LogViewPlus must all follow the same schema.
By ofir - 29 Feb 2024

Hi I noticed that if the JSON file is compressed, it detects only the first entry...

The compress one:
{"Entries":[{"Type":"Internal","Message":"message","StackTrace":"","Time":"09:12:31"},{"Type":"Internal","Message":"messsssssssage","StackTrace":"","Time":"09:12:32"},{"Type":"Warning","Message":"The referenced script on this Behaviour (Game Object 'Copper_Bend_JNT_8') is missing!","StackTrace":"fsdfsdfsdfsd fsd fsdf sdf ","Time":"09:12:34"},{"Type":"Exception","Message":"NullReferenceException: Object reference not set to an instance of an object","StackTrace":"fsdfsd fds fdsf sdf ","Time":"09:12:44"}]}

The aligned one:
{
"Entries": [
{
"Type": "Internal",
"Message": "message",
"StackTrace": "",
"Time": "09:12:31"
},
{
"Type": "Internal",
"Message": "messsssssssage",
"StackTrace": "",
"Time": "09:12:32"
},
{
"Type": "Warning",
"Message": "The referenced script on this Behaviour (Game Object 'Copper_Bend_JNT_8') is missing!",
"StackTrace": "fsdfsdfsdfsd fsd fsdf sdf ",
"Time": "09:12:34"
},
{
"Type": "Exception",
"Message": "NullReferenceException: Object reference not set to an instance of an object",
"StackTrace": "fsdfsd fds fdsf sdf ",
"Time": "09:12:44"
}
]
}


I just want to avoid formatting it every time I want to read the logs... Do you have any solutions? 
By LogViewPlus Support - 29 Feb 2024

The built-in LogViewPlus parsers expect a maximum of one log entry per log line.  It appears your log file is written all at once rather than line by line.

Unfortunately, this assumption is built into the parser interface, so this will not be something we can work around.  The only way to process this file in LogViewPlus would be to develop a Custom Reader.  Your implementation would need to parse the entire log file and then return all log entries as a batch.

Hope that helps,

Toby