Splunk Search

How to break nested objects and lists into individual events?

dasaed
Explorer

I have an event with multiple levels of nested objects and lists, that I need to break down into individual events. For example, a single event can look like:

dasaed_0-1645198215353.png

 

And I need to conver that event into a table like this:

Group_name

Sub_group

Subsubgroup

Some other info …

alpha

alpha1

beta

 

alpha

alpha1

gamma

 

alpha

alpha2

a

 

alpha

alpha2

b

 

alpha

alpha3

uno

 

 

I've tried multiple combinations of mvexpand, table, and stats, but I keep getting erroneous results. The command flatten doesn't seem to work, and I fear I might need some crazy regex to parse all the embedded objects and list of objects, not to mention this is only one event, in reality I would have multiple other groups with their corresponding subgroups and stuff. 

Labels (1)
0 Karma
1 Solution

yuanliu
SplunkTrust
SplunkTrust

First of all, please post sample data in text, not in screenshot.  It is much easier for other people to help.

Secondly, the screenshot shows invalid JSON syntax.

Assuming actual data are conformant, the following should give you the desired outcome

 

| spath path=group_name
| spath output=sub_groups path=group.sub_groups{}
| mvexpand sub_groups
| spath input=sub_groups path=subgroup
| spath input=sub_groups output=subsubgroup path=subsubgroup{}
| fields - sub_groups ``` just to clear view, not part of calculation ```
| mvexpand subsubgroup
| spath input=subsubgroup
| table group_name subgroup team "some other info"

 

In the above, I didn't bother to rename fields; for example, "team" is subsubgroup, etc.  In input data, I assumed that there is a field "some other info" under subsubgroup.

Given test data as follows (which you should have supplied in text):

 

{"event":"A",
  "group_name":"alpha",
  "group":{
    "group_name":"alpha",
    "sub_groups":[
     {"subgroup":"alpha1",
      "subsubgroup": [
        {"team":"beta"},
        {"team":"gamma", "some other info":"foo"}]
     },
     {"subgroup":"alpha2",
      "subsubgroup": [
       {"team":"a"},
       {"team":"b", "some other info":"bar"}]
     },
     {"subgroup": "alpha3",
      "subsubgroup": [
       {"team": "uno", "some other info":"baz"}]
     }
   ]
  }
}

 

output would be

group_namesubgroupteamsome other info
alphaalpha1beta 
alphaalpha1gammafoo
alphaalpha2a 
alphaalpha2bbar
alphaalpha3unobaz

View solution in original post

Tags (2)

yuanliu
SplunkTrust
SplunkTrust

First of all, please post sample data in text, not in screenshot.  It is much easier for other people to help.

Secondly, the screenshot shows invalid JSON syntax.

Assuming actual data are conformant, the following should give you the desired outcome

 

| spath path=group_name
| spath output=sub_groups path=group.sub_groups{}
| mvexpand sub_groups
| spath input=sub_groups path=subgroup
| spath input=sub_groups output=subsubgroup path=subsubgroup{}
| fields - sub_groups ``` just to clear view, not part of calculation ```
| mvexpand subsubgroup
| spath input=subsubgroup
| table group_name subgroup team "some other info"

 

In the above, I didn't bother to rename fields; for example, "team" is subsubgroup, etc.  In input data, I assumed that there is a field "some other info" under subsubgroup.

Given test data as follows (which you should have supplied in text):

 

{"event":"A",
  "group_name":"alpha",
  "group":{
    "group_name":"alpha",
    "sub_groups":[
     {"subgroup":"alpha1",
      "subsubgroup": [
        {"team":"beta"},
        {"team":"gamma", "some other info":"foo"}]
     },
     {"subgroup":"alpha2",
      "subsubgroup": [
       {"team":"a"},
       {"team":"b", "some other info":"bar"}]
     },
     {"subgroup": "alpha3",
      "subsubgroup": [
       {"team": "uno", "some other info":"baz"}]
     }
   ]
  }
}

 

output would be

group_namesubgroupteamsome other info
alphaalpha1beta 
alphaalpha1gammafoo
alphaalpha2a 
alphaalpha2bbar
alphaalpha3unobaz
Tags (2)
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 ...