Getting Data In

How can I query and find records which have an empty array?

dreddy123
New Member

My JSON looks like this,

{
"id":"studentNumber",
"courses" : [ {
"course" : "Analysis of Alg"
},
{
"course": "game dev"
}

]

}

I would like to get all the student numbers who haven't registered for any courses --> where "courses" array is empty.

Tags (2)
0 Karma

kamlesh_vaghela
SplunkTrust
SplunkTrust

@ dreddy123

Can you please try this?

YOUR_SEARCH  | rename courses{}.course as courses_course | where isnull(courses_course) 

My Sample Search:

| makeresults | eval _raw="{\"id\":\"studentNumber\",\"courses\":[{\"course\" : \"Analysis of Alg\"},{\"course\": \"game dev\"}]}" | append [ | makeresults | eval _raw="{\"id\":\"studentNumber\",\"courses\":[]}" ] |kv | rename courses{}.course as courses_course | where isnull(courses_course)

Thanks

0 Karma

nrduren1115
Explorer

Does courses show up as a field in those events? If not, you can use | where isnull(courses)

0 Karma

dreddy123
New Member

{
"id":"studentNumber",
"courses" : [ ]
}
it will show up like this when no courses are registered.

0 Karma

nrduren1115
Explorer

To be a bit more specific, is courses extracted as a field and if so, what is the value?

0 Karma
Get Updates on the Splunk Community!

Now Available: Cisco Talos Threat Intelligence Integrations for Splunk Security Cloud ...

At .conf24, we shared that we were in the process of integrating Cisco Talos threat intelligence into Splunk ...

Preparing your Splunk Environment for OpenSSL3

The Splunk platform will transition to OpenSSL version 3 in a future release. Actions are required to prepare ...

Easily Improve Agent Saturation with the Splunk Add-on for OpenTelemetry Collector

Agent Saturation What and Whys In application performance monitoring, saturation is defined as the total load ...