Getting Data In

Create Splunk Table from nested json output

niddhi
Explorer

Hi,

Can someone please help me create a Splunk Table from the below data:

 

{
   "cd":[
      {
         "cn":"cust-1",
         "s":"api",
         "ps":61,
         "fs":94,
         "es":142,
         "ud":[
            {
               "un":"user-0",
               "ps":61,
               "fs":94,
               "es":142,
               "ad":[
                  {
                     "at":"asset2",
                     "ps":61,
                     "fs":94,
                     "es":142,
                     "ttd":[
                        {
                           "tt":null,
                           "ps":61,
                           "fs":94,
                           "es":142
                        }
                     ]
                  }
               ]
            }
         ]
      },
      {
         "cn":"cust-2",
         "s":"api",
         "ps":727,
         "fs":152,
         "es":26,
         "ud":[
            {
               "un":"user-6",
               "ps":725,
               "fs":149,
               "es":21,
               "ad":[
                  {
                     "at":"asset1",
                     "ps":722,
                     "fs":149,
                     "es":20,
                     "ttd":[
                        {
                           "tt":null,
                           "ps":722,
                           "fs":149,
                           "es":20
                        }
                     ]
                  },
                  {
                     "at":"asset2",
                     "ps":3,
                     "fs":0,
                     "es":1,
                     "ttd":[
                        {
                           "tt":null,
                           "ps":3,
                           "fs":0,
                           "es":1
                        }
                     ]
                  }
               ]
            },
            {
               "un":"user1",
               "ps":1,
               "fs":0,
               "es":0,
               "ad":[
                  {
                     "at":"asset1",
                     "ps":1,
                     "fs":0,
                     "es":0,
                     "ttd":[
                        {
                           "tt":null,
                           "ps":1,
                           "fs":0,
                           "es":0
                        }
                     ]
                  }
               ]
            },
            {
               "un":"user2",
               "ps":1,
               "fs":3,
               "es":5,
               "ad":[
                  {
                     "at":"asset2",
                     "ps":1,
                     "fs":3,
                     "es":5,
                     "ttd":[
                        {
                           "tt":null,
                           "ps":1,
                           "fs":3,
                           "es":5
                        }
                     ]
                  }
               ]
            }
         ]
      },
      {
         "cn":"cust-3",
         "s":"api",
         "ps":0,
         "fs":1,
         "es":0,
         "ud":[
            {
               "un":"user-3",
               "ps":0,
               "fs":1,
               "es":0,
               "ad":[
                  {
                     "at":"asset2",
                     "ps":0,
                     "fs":1,
                     "es":0,
                     "ttd":[
                        {
                           "tt":null,
                           "ps":0,
                           "fs":1,
                           "es":0
                        }
                     ]
                  }
               ]
            }
         ]
      },
      {
         "cn":"cust-4",
         "s":"api",
         "ps":1,
         "fs":4,
         "es":22,
         "ud":[
            {
               "un":"user-4",
               "ps":1,
               "fs":4,
               "es":22,
               "ad":[
                  {
                     "at":"asset1",
                     "ps":1,
                     "fs":4,
                     "es":22,
                     "ttd":[
                        {
                           "tt":null,
                           "ps":1,
                           "fs":4,
                           "es":22
                        }
                     ]
                  }
               ]
            }
         ]
      }
   ]
}

 

 

I want the output to be like:

cnunatttpsfses
cust-1

user-0

asset2

null6194142
cust-2

user-6

 

user1

user2

asset1

asset2

asset1

asset2

null

null

null

null

722

3

1

1

149

0

0

3

20

1

0

5

cust-3user-3asset2null010
cust4user-4asset1null1422

 

Thanks in advance.

Labels (1)
0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust
| makeresults | eval _raw="{
   \"cd\":[
      {
         \"cn\":\"cust-1\",
         \"s\":\"api\",
         \"ps\":61,
         \"fs\":94,
         \"es\":142,
         \"ud\":[
            {
               \"un\":\"user-0\",
               \"ps\":61,
               \"fs\":94,
               \"es\":142,
               \"ad\":[
                  {
                     \"at\":\"asset2\",
                     \"ps\":61,
                     \"fs\":94,
                     \"es\":142,
                     \"ttd\":[
                        {
                           \"tt\":null,
                           \"ps\":61,
                           \"fs\":94,
                           \"es\":142
                        }
                     ]
                  }
               ]
            }
         ]
      },
      {
         \"cn\":\"cust-2\",
         \"s\":\"api\",
         \"ps\":727,
         \"fs\":152,
         \"es\":26,
         \"ud\":[
            {
               \"un\":\"user-6\",
               \"ps\":725,
               \"fs\":149,
               \"es\":21,
               \"ad\":[
                  {
                     \"at\":\"asset1\",
                     \"ps\":722,
                     \"fs\":149,
                     \"es\":20,
                     \"ttd\":[
                        {
                           \"tt\":null,
                           \"ps\":722,
                           \"fs\":149,
                           \"es\":20
                        }
                     ]
                  },
                  {
                     \"at\":\"asset2\",
                     \"ps\":3,
                     \"fs\":0,
                     \"es\":1,
                     \"ttd\":[
                        {
                           \"tt\":null,
                           \"ps\":3,
                           \"fs\":0,
                           \"es\":1
                        }
                     ]
                  }
               ]
            },
            {
               \"un\":\"user1\",
               \"ps\":1,
               \"fs\":0,
               \"es\":0,
               \"ad\":[
                  {
                     \"at\":\"asset1\",
                     \"ps\":1,
                     \"fs\":0,
                     \"es\":0,
                     \"ttd\":[
                        {
                           \"tt\":null,
                           \"ps\":1,
                           \"fs\":0,
                           \"es\":0
                        }
                     ]
                  }
               ]
            },
            {
               \"un\":\"user2\",
               \"ps\":1,
               \"fs\":3,
               \"es\":5,
               \"ad\":[
                  {
                     \"at\":\"asset2\",
                     \"ps\":1,
                     \"fs\":3,
                     \"es\":5,
                     \"ttd\":[
                        {
                           \"tt\":null,
                           \"ps\":1,
                           \"fs\":3,
                           \"es\":5
                        }
                     ]
                  }
               ]
            }
         ]
      },
      {
         \"cn\":\"cust-3\",
         \"s\":\"api\",
         \"ps\":0,
         \"fs\":1,
         \"es\":0,
         \"ud\":[
            {
               \"un\":\"user-3\",
               \"ps\":0,
               \"fs\":1,
               \"es\":0,
               \"ad\":[
                  {
                     \"at\":\"asset2\",
                     \"ps\":0,
                     \"fs\":1,
                     \"es\":0,
                     \"ttd\":[
                        {
                           \"tt\":null,
                           \"ps\":0,
                           \"fs\":1,
                           \"es\":0
                        }
                     ]
                  }
               ]
            }
         ]
      },
      {
         \"cn\":\"cust-4\",
         \"s\":\"api\",
         \"ps\":1,
         \"fs\":4,
         \"es\":22,
         \"ud\":[
            {
               \"un\":\"user-4\",
               \"ps\":1,
               \"fs\":4,
               \"es\":22,
               \"ad\":[
                  {
                     \"at\":\"asset1\",
                     \"ps\":1,
                     \"fs\":4,
                     \"es\":22,
                     \"ttd\":[
                        {
                           \"tt\":null,
                           \"ps\":1,
                           \"fs\":4,
                           \"es\":22
                        }
                     ]
                  }
               ]
            }
         ]
      }
   ]
}"
| spath path=cd{} output=cd
| fields - _*
| mvexpand cd
| spath input=cd path=ud{} output=ud
| rex field=cd "\"cn\":\"(?<cn>[^\"]+)"
| fields - cd
| mvexpand ud
| spath input=ud path=ad{} output=ad
| rex field=ud "\"un\":\"(?<un>[^\"]+)"
| fields - ud
| mvexpand ad
| spath input=ad path=ttd{} output=ttd
| rex field=ad "\"at\":\"(?<at>[^\"]+)"
| fields - ad
| spath input=ttd
| fields - ttd
| table cn un at tt ps fs es

View solution in original post

ITWhisperer
SplunkTrust
SplunkTrust
| makeresults | eval _raw="{
   \"cd\":[
      {
         \"cn\":\"cust-1\",
         \"s\":\"api\",
         \"ps\":61,
         \"fs\":94,
         \"es\":142,
         \"ud\":[
            {
               \"un\":\"user-0\",
               \"ps\":61,
               \"fs\":94,
               \"es\":142,
               \"ad\":[
                  {
                     \"at\":\"asset2\",
                     \"ps\":61,
                     \"fs\":94,
                     \"es\":142,
                     \"ttd\":[
                        {
                           \"tt\":null,
                           \"ps\":61,
                           \"fs\":94,
                           \"es\":142
                        }
                     ]
                  }
               ]
            }
         ]
      },
      {
         \"cn\":\"cust-2\",
         \"s\":\"api\",
         \"ps\":727,
         \"fs\":152,
         \"es\":26,
         \"ud\":[
            {
               \"un\":\"user-6\",
               \"ps\":725,
               \"fs\":149,
               \"es\":21,
               \"ad\":[
                  {
                     \"at\":\"asset1\",
                     \"ps\":722,
                     \"fs\":149,
                     \"es\":20,
                     \"ttd\":[
                        {
                           \"tt\":null,
                           \"ps\":722,
                           \"fs\":149,
                           \"es\":20
                        }
                     ]
                  },
                  {
                     \"at\":\"asset2\",
                     \"ps\":3,
                     \"fs\":0,
                     \"es\":1,
                     \"ttd\":[
                        {
                           \"tt\":null,
                           \"ps\":3,
                           \"fs\":0,
                           \"es\":1
                        }
                     ]
                  }
               ]
            },
            {
               \"un\":\"user1\",
               \"ps\":1,
               \"fs\":0,
               \"es\":0,
               \"ad\":[
                  {
                     \"at\":\"asset1\",
                     \"ps\":1,
                     \"fs\":0,
                     \"es\":0,
                     \"ttd\":[
                        {
                           \"tt\":null,
                           \"ps\":1,
                           \"fs\":0,
                           \"es\":0
                        }
                     ]
                  }
               ]
            },
            {
               \"un\":\"user2\",
               \"ps\":1,
               \"fs\":3,
               \"es\":5,
               \"ad\":[
                  {
                     \"at\":\"asset2\",
                     \"ps\":1,
                     \"fs\":3,
                     \"es\":5,
                     \"ttd\":[
                        {
                           \"tt\":null,
                           \"ps\":1,
                           \"fs\":3,
                           \"es\":5
                        }
                     ]
                  }
               ]
            }
         ]
      },
      {
         \"cn\":\"cust-3\",
         \"s\":\"api\",
         \"ps\":0,
         \"fs\":1,
         \"es\":0,
         \"ud\":[
            {
               \"un\":\"user-3\",
               \"ps\":0,
               \"fs\":1,
               \"es\":0,
               \"ad\":[
                  {
                     \"at\":\"asset2\",
                     \"ps\":0,
                     \"fs\":1,
                     \"es\":0,
                     \"ttd\":[
                        {
                           \"tt\":null,
                           \"ps\":0,
                           \"fs\":1,
                           \"es\":0
                        }
                     ]
                  }
               ]
            }
         ]
      },
      {
         \"cn\":\"cust-4\",
         \"s\":\"api\",
         \"ps\":1,
         \"fs\":4,
         \"es\":22,
         \"ud\":[
            {
               \"un\":\"user-4\",
               \"ps\":1,
               \"fs\":4,
               \"es\":22,
               \"ad\":[
                  {
                     \"at\":\"asset1\",
                     \"ps\":1,
                     \"fs\":4,
                     \"es\":22,
                     \"ttd\":[
                        {
                           \"tt\":null,
                           \"ps\":1,
                           \"fs\":4,
                           \"es\":22
                        }
                     ]
                  }
               ]
            }
         ]
      }
   ]
}"
| spath path=cd{} output=cd
| fields - _*
| mvexpand cd
| spath input=cd path=ud{} output=ud
| rex field=cd "\"cn\":\"(?<cn>[^\"]+)"
| fields - cd
| mvexpand ud
| spath input=ud path=ad{} output=ad
| rex field=ud "\"un\":\"(?<un>[^\"]+)"
| fields - ud
| mvexpand ad
| spath input=ad path=ttd{} output=ttd
| rex field=ad "\"at\":\"(?<at>[^\"]+)"
| fields - ad
| spath input=ttd
| fields - ttd
| table cn un at tt ps fs es

niddhi
Explorer

Saved my day. This works perfectly. Thank you so much!!

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Splunk Add-on for Microsoft Windows 11.0.3: Parse Once, Search Faster

The updated Splunk Add-on for Microsoft Windows helps customers search Windows events faster by reducing ...

What's New in Splunk Enterprise Security 8.8 and Beyond

Threats move at machine speed. Keeping up should not depend on having the biggest budget, the largest team, or ...

A Four-Part Event Series: State of Observability - Where AI Meets Performance

As AI agents take on more complex tasks, teams need greater visibility into how they behave, what they cost, ...