Splunk Search

How to extract and download a field of array from an event?

hantaliu
Loves-to-Learn Lots

I have an event which is constructed like the following:

 

{
   name: string,
   time: string,
   duration: string,
   logs: JSONObjects[]
}

 

When I download the event, I just want the logs which is everything inside [] but without the head part which is "{logs:" and the last "}"

To do that how do I construct the search query? 

Tags (2)
0 Karma

rymundo_splunk
Splunk Employee
Splunk Employee

Hi, you could use something like spath to process the json and then pick the logs array out of the resultant object.  Maybe something like this:


|makeresults
| eval json="{\"name\":\"json_name\", \"logs\":[{\"name\":\"log1\"}, { \"name\":\"log2\"}]}",
output_log_array=spath(json,"logs{}"),
output_log_names=spath(json,"logs{}.name")

I added a second example with output_log_names to show how you would extract particular fields within the array json into their own multivalued field. 

 

rymundo_splunk_0-1655944499206.png

 

 

0 Karma
Get Updates on the Splunk Community!

Index This | Why did the turkey cross the road?

November 2025 Edition  Hayyy Splunk Education Enthusiasts and the Eternally Curious!   We’re back with this ...

Enter the Agentic Era with Splunk AI Assistant for SPL 1.4

  🚀 Your data just got a serious AI upgrade — are you ready? Say hello to the Agentic Era with the ...

Feel the Splunk Love: Real Stories from Real Customers

Hello Splunk Community,    What’s the best part of hearing how our customers use Splunk? Easy: the positive ...