Getting Data In

How to run a nested loop?

aditya
Engager

Hi,

I have one field containing an array within an array.

How can I run a for loop to query the nested arrays and display them?

Eg :-

Dept_details : [

{name:"cse", HOD:"somename", students:[

{name:"aditya", rollNo:"1"}, {name:"akash", rollNo="2"}

]

},

{

name:"ece", HOD:"somename2", students:[

{name:"abhiram", rollNo:"1"}, {name:"abhay", rollNo="2"}

]

}

]

 

I expect the results to be like this :-

Dept_details

name                    hod

cse                        someone

 

student details

name                 rollNo

aditya                1

akash                  2

 

dept details

name                    hod

ise                        someone2

 

student details

name                 rollNo

abhiram           1

abhay               2

 

Thanks,

Aditya

Labels (2)
0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust

I am not sure you can easily get the representation you are showing, however,  you could try something like this to break up the data

| spath path=Dept_details output=Dept_details
| mvexpand Dept_details
| spath input=Dept_details

View solution in original post

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

I am not sure you can easily get the representation you are showing, however,  you could try something like this to break up the data

| spath path=Dept_details output=Dept_details
| mvexpand Dept_details
| spath input=Dept_details
0 Karma

aditya
Engager

Hi @ITWhisperer ,

The events which are getting logged for my project can have same id. So, on running mvexpand, it lists the contents of all array of all events. That's why I need to run a for loop somehow. Otherwise I can't calculate no of depts in dept_details.

Can you help with this?

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

I am not sure where id is coming from since it isn't in the example you shared - if you need the count of dept_details

| spath path=Dept_details output=Dept_details
| eval Dep_t_count=mvcount(Dept_details)
0 Karma

aditya
Engager

Ok, got it. Thanks for your help!!

0 Karma
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...