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!

Splunk Observability for AI

Don’t miss out on an exciting Tech Talk on Splunk Observability for AI! Discover how Splunk’s agentic AI ...

[Puzzles] Solve, Learn, Repeat: Dereferencing XML to Fixed-length events

This challenge was first posted on Slack #puzzles channelFor a previous puzzle, I needed a set of fixed-length ...

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

What are Community Office Hours? Community Office Hours is an interactive 60-minute Zoom series where ...