3

I need to grab the value of the first entry in a json array with Kusto KQL in Microsoft Defender ATP.

The data format looks like this (anonymized), and I want the value of "UserName":

[{"UserName":"xyz","DomainName":"xyz","Sid":"xyz"}]

How do I split or in any other way get the "UserName" value?

3 Answers 3

2

In WDATP/MSTAP, for the "LoggedOnUsers" type of arrays, you want "mv-expand" (multi-value expand) in conjunction with "parsejson".

"parsejson" will turn the string into JSON, and mv-expand will expand it into LoggedOnUsers.Username, LoggedOnUsers.DomainName, and LoggedOnUsers.Sid:

DeviceInfo 
| mv-expand parsejson(LoggedOnUsers)
| project DeviceName, LoggedOnUsers.UserName, LoggedOnUsers.DomainName

Keep in mind that if the packed field has multiple entries (like DeviceNetworkInfo's IPAddresses field often does), the entire row will be expanded once per entry - so a row for a machine with 3 entries in "IPAddresses" will be duplicated 3 times, with each different expansion of IpAddresses:

DeviceNetworkInfo 
| where Timestamp > ago(1h)
| mv-expand parsejson(IPAddresses)
| project DeviceName, IPAddresses.IPAddress
Sign up to request clarification or add additional context in comments.

1 Comment

This(your approach) is super easy, Thank you very much....
1

to access the first entry's UserName property you can do the following:

print d = dynamic([{"UserName":"xyz","DomainName":"xyz","Sid":"xyz"}])
| extend result = d[0].UserName

to get the UserName for all entries, you can use mv-expand/mv-apply:

print d = dynamic([{"UserName":"xyz","DomainName":"xyz","Sid":"xyz"}])
| mv-apply d on (
    project d.UserName
)

Comments

-1

thanks for the reply, but the proposed solution didn't work for me. However instead I found the following solution:

project substring(split(split(LoggedOnUsers,',',0),'"',4),2,9)

The output of this is: UserName

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.