Splunk Search

How to filter data from JSON object having one field name and list of values into table?

Splunk_321
Path Finder

I have data something like below.

 msg: { 
     applicationtest-app
     correlationid0.59680117.1667864418.7d2b8d5
     httpmethodGET
     levelINFO
     logMessage: { 
       apiNametestApi
       apiStatusSuccess
       clientIdtestClientId1
       errorNA
       list_items: [
         { 
           cityPHOENIX
           countryCodeUSA
           locationIddc5269a4-c043-4381-b757-63950feecac3
           matchRank1
           merchantNametestMerchant1
           postalCode12345
           stateAZ
           streetAddress4000 E SKY HARBOR BLVD
         }
         { 
           cityPHOENIX
           countryCodeUSA
           locationIdc7b97f03-b21b-4c11-aead-1ca3cd03d415
           matchRank2
           merchantNametestMerchant2
           postalCode56789
           stateAZ
           streetAddress4000 E SKY HARBOR BL
         }

      ......

    ]

I have to get a table with clientId and locationId something like below 

clientId                     locationId

testClientId1         dc5269a4-c043-4381-b757-63950feecac3

testClientId1         c7b97f03-b21b-4c11-aead-1ca3cd03d415

What I tried is | base search | | table "msg.logMessage.clientId", "msg.logMessage.matched_locations{}.locationId" 

which resulted in grouping the locationIds for clientId hence one row for even multiple locationIds

clientId                     locationId

testClientId1         dc5269a4-c043-4381-b757-63950feecac3

                                    c7b97f03-b21b-4c11-aead-1ca3cd03d415

Any help is appreciated. 

Labels (1)
0 Karma
1 Solution

richgalloway
SplunkTrust
SplunkTrust

Use the mvexpand command to put the locationId values on different rows.

| base search | 
| table "msg.logMessage.clientId", "msg.logMessage.matched_locations{}.locationId" 
| mvexpand "msg.logMessage.matched_locations{}.locationId"

 

---
If this reply helps you, Karma would be appreciated.

View solution in original post

richgalloway
SplunkTrust
SplunkTrust

Use the mvexpand command to put the locationId values on different rows.

| base search | 
| table "msg.logMessage.clientId", "msg.logMessage.matched_locations{}.locationId" 
| mvexpand "msg.logMessage.matched_locations{}.locationId"

 

---
If this reply helps you, Karma would be appreciated.
Get Updates on the Splunk Community!

Leveraging Detections from the Splunk Threat Research Team & Cisco Talos

  Now On Demand  Stay ahead of today’s evolving threats with the combined power of the Splunk Threat Research ...

New in Splunk Observability Cloud: Automated Archiving for Unused Metrics

Automated Archival is a new capability within Metrics Management; which is a robust usage & cost optimization ...

Calling All Security Pros: Ready to Race Through Boston?

Hey Splunkers, .conf25 is heading to Boston and we’re kicking things off with something bold, competitive, and ...