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!

Aligning Observability Costs with Business Value: Practical Strategies

 Join us for an engaging Tech Talk on Aligning Observability Costs with Business Value: Practical ...

Mastering Data Pipelines: Unlocking Value with Splunk

 In today's AI-driven world, organizations must balance the challenges of managing the explosion of data with ...

Splunk Up Your Game: Why It's Time to Embrace Python 3.9+ and OpenSSL 3.0

Did you know that for Splunk Enterprise 9.4, Python 3.9 is the default interpreter? This shift is not just a ...