Help converting Windows Event to JSON

View thread

Ryan1234 (Last updated )

Hi,

I’m leveraging the to_json() function to convert Windows Events to JSON before sending them. This generally works well, and most of the log is converted to JSON correctly. However, there’s a portion of the log where NXLog doesn’t format the data into proper JSON, instead inserting control characters like \r\n. This breaks the JSON formatting and results in an undesirable output.

Here’s an example of a Windows Event that’s been converted to JSON. As you can see, the Message field includes control characters and retains the original structure of the event rather than being properly formatted as JSON:

{"Channel":"Security","Message": "System audit policy was changed.\r\n\r\nSubject:\r\n\tSecurity ID:\t\tS-1-5-18\r\n\tAccount Name:\t\tclient01$\r\n\tAccount Domain:\t\tmydomain\r\n\tLogon ID:\t\t0x3E7\r\n\r\nAudit Policy Change:\r\n\tCategory:\t\tAccount Logon\r\n\tSubcategory:\t\tKerberos Service Ticket Operations\r\n\tSubcategory GUID:\t{foo}\r\n\tChanges:\t\tSuccess removed, Failure removed","Category":"Audit Policy Change"}

Here’s an example of the output I’d like to achieve:

{"Channel":"Security","Message":"System audit policy was changed.", "Subject":{"Security ID": "S-1-5-18","Account Name":"client01$","Account Domain":"mydomain","Logon ID":"0x3E7"},"Audit Policy Change":{"Category":"Account Logon","Subcategory":"Kerberos Service Ticket Operations","Subcategory GUID":"{foo}","Changes":"Success removed, Failure removed"},"Category":"Audit Policy Change"}

Does anyone know if and how I can achieve this?

NXLog CE is running on Windows Server 2022. Package version is 3.2.2329.