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!

Observability Release Update: AI Assistant, AppD + Observability Cloud Integrations & ...

This month’s releases across the Splunk Observability portfolio deliver earlier detection and faster ...

Stay Connected: Your Guide to February Tech Talks, Office Hours, and Webinars!

💌Keep the new year’s momentum going with our February lineup of Community Office Hours, Tech Talks, ...

Preparing your Splunk Environment for OpenSSL3

The Splunk platform will transition to OpenSSL version 3 in a future release. Actions are required to prepare ...