Splunk Search

How to break JSON for individual values

msrama5
Explorer

Hello, I want to break the TestTransaction inside testVal values, JSON needs to break up and show all field values inside JSON, how can this search be rewritten?

Splunk search:

index=* sourcetype=WORKER | fields TestVal

TestVal values:

{"@t":"2020-02-04T22:16:20.8458700Z","@mt":"{@parameters}","parameters":{"info":"Published","message":{"TestTransaction":{"sampleval":"10298684736384305384235533777352","EntryType":141,"CheckNumber":783562,"CheckCloseDate":"2020-02-04T22:16:08.0000000Z","CurrencyCode":"USD","Tenders":[{"Amount":5.3,"Description":"SBUX Card","TenderId":"SV5j8AtfYVm","SvcVal":6147524390259141,"CurrencyCode":null,"$type":"TestTender"}],"TotalAmount":5.3,"SubtotalAmount":4.95,"TaxAmount":0.35,"DiscountAmount":0.0,"Header":{"ServiceType":null,"Number":22,"PosRequestDate":"2020-02-04T22:16:08.0000000Z","$type":"TestHeader"},"Preparation":"ConsumeOutOfStore","TestDetails":{"Discounts":[],"Items":[{"Qty":1.0,"Sku":null,"Price":4.95,"Discounts":[],"Description":null,"Price":null,"Suffix":null,"ChildItems":[],"Commerce":{"Sku":"11105767","edSku":null,"PosStatus":null,"Value":null,"$type":"Commerce"},"Product":{"ProductTypeId":11,"ProductType":"Beverage","ProductNumber":2123078,"FormCode":"salty","SizeCode":"test","LocalDescription":"test","$type":"Product"},"IsRefunded":false,"IsTaxed":false,"Summary":{"TotalPrice":4.95,"DiscountAmount":0,"SubtotalAmount":4.95,"$type":"TestItemSummary"},"$type":"TestItem"}],"Taxes":[{"Name":"State+Local Meals Tax 7%","Amount":35,"$type":"TestTax"}],"ReceiptLines":[],"Delivery":null,"$type":"TestDetails"},"$type":"TestTransaction"},"RequestId":"pos-200204141619-prodrh50592773796","MessageId":"BTxnApi_MID_b6cea268-af3c-4334-85df-c34108e81705","$type":"UpsertTestTransaction"}}}
0 Karma
1 Solution

to4kawa
Ultra Champion
 index=* sourcetype=WORKER
| fields TestVal
| spath input=TestVal
| fields - TestVal

View solution in original post

0 Karma

to4kawa
Ultra Champion
 index=* sourcetype=WORKER
| fields TestVal
| spath input=TestVal
| fields - TestVal
0 Karma

msrama5
Explorer

Thanks everyone for answering, above query is working

0 Karma

vnravikumar
Champion

Hi

Check this

| makeresults 
| eval TestVal="{ 
   \"@t\":\"2020-02-04T22:16:20.8458700Z\",
   \"@mt\":\"{@parameters}\",
   \"parameters\":{ 
      \"info\":\"Published\",
      \"message\":{ 
         \"TestTransaction\":{ 
            \"sampleval\":\"10298684736384305384235533777352\",
            \"EntryType\":141,
            \"CheckNumber\":783562,
            \"CheckCloseDate\":\"2020-02-04T22:16:08.0000000Z\",
            \"CurrencyCode\":\"USD\",
            \"Tenders\":[ 
               { 
                  \"Amount\":5.3,
                  \"Description\":\"SBUX Card\",
                  \"TenderId\":\"SV5j8AtfYVm\",
                  \"SvcVal\":6147524390259141,
                  \"CurrencyCode\":null,
                  \"$type\":\"TestTender\"
                       }
            ],
            \"TotalAmount\":5.3,
            \"SubtotalAmount\":4.95,
            \"TaxAmount\":0.35,
            \"DiscountAmount\":0.0,
            \"Header\":{ 
               \"ServiceType\":null,
               \"Number\":22,
               \"PosRequestDate\":\"2020-02-04T22:16:08.0000000Z\",
               \"$type\":\"TestHeader\"
                    },
            \"Preparation\":\"ConsumeOutOfStore\",
            \"TestDetails\":{ 
               \"Discounts\":[ 

               ],
               \"Items\":[ 
                  { 
                     \"Qty\":1.0,
                     \"Sku\":null,
                     \"Price\":4.95,
                     \"Discounts\":[ 

                     ],
                     \"Description\":null,
                     \"Price\":null,
                     \"Suffix\":null,
                     \"ChildItems\":[ 

                     ],
                     \"Commerce\":{ 
                        \"Sku\":\"11105767\",
                        \"edSku\":null,
                        \"PosStatus\":null,
                        \"Value\":null,
                        \"$type\":\"Commerce\"
                             },
                     \"Product\":{ 
                        \"ProductTypeId\":11,
                        \"ProductType\":\"Beverage\",
                        \"ProductNumber\":2123078,
                        \"FormCode\":\"salty\",
                        \"SizeCode\":\"test\",
                        \"LocalDescription\":\"test\",
                        \"$type\":\"Product\"
                             },
                     \"IsRefunded\":false,
                     \"IsTaxed\":false,
                     \"Summary\":{ 
                        \"TotalPrice\":4.95,
                        \"DiscountAmount\":0,
                        \"SubtotalAmount\":4.95,
                        \"$type\":\"TestItemSummary\"
                             },
                     \"$type\":\"TestItem\"
                          }
               ],
               \"Taxes\":[ 
                  { 
                     \"Name\":\"State+Local Meals Tax 7%\",
                     \"Amount\":35,
                     \"$type\":\"TestTax\"
                          }
               ],
               \"ReceiptLines\":[ 

               ],
               \"Delivery\":null,
               \"$type\":\"TestDetails\"
                    },
            \"$type\":\"TestTransaction\"
                 },
         \"RequestId\":\"pos-200204141619-prodrh50592773796\",
         \"MessageId\":\"BTxnApi_MID_b6cea268-af3c-4334-85df-c34108e81705\",
         \"$type\":\"UpsertTestTransaction\"
              }
   }
}" 
| spath input=TestVal path=parameters.message.TestTransaction output=TestTransaction 
| spath input=TestTransaction
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!

Deep Dive: Accelerate threat investigation with Splunk’s AI Assistant in Security

AI is one of the biggest topics in the market today, and for security teams, its value goes far beyond the ...

Announcing Modern Navigation: A New Era of Splunk User Experience

We are excited to introduce the Modern Navigation feature in the Splunk Platform, available to both cloud and ...

Detection Engineering Office Hours: Real-World Troubleshooting & Q&A

[REGISTER HERE] This thread is for the Community Office Hours session on Detection Engineering Office Hours: ...