Getting Data In

How to parse JSON data with spath and table the data.

adibrr16
New Member

Hi

I am trying to parse this json using spath. I am not able to parse "data" element.

{  
   "id":"eab50eea-4b3c-4ca1-9c59-eb66500b57ea",
   "severity":"Error",
   "data":{  
      "CallingMethod":"UpdResponse",
      "ClientRequestId":"8fb58962-88df-4fa4-b787-163c3bca92b0",
      "SourceTransactionId":"9344949-ABS",
      "OrderType":"Domestic",
      "Errors":[  
         {  
            "ErrNumber":14076,
            "Message":"SE 2 already exists in OTC."
         },
         {  
            "ErrNumber":14076,
            "Message":"SE 3 already exists in OTC."
         }
      ],
      "Level":"Error",
      "TimeStamp":"4/19/2018 1:07:15 PM"
   }
}

Planning to show data in tabular format

id | severity | SourceTransactionId | ErrNumber | Message

I tried some queries bust was not successful.

source="otc" severity="error" 
| spath data{} output=data 
| stats count by severity data 
| eval _raw=data 
| spath Errors{} output=Errors 
| spath CallingMethod output=CallingMethod 
| stats count by severity CallingMethod Errors 
| eval _raw=Erors | spath ErrNumber output=ErrNumber | spath Message output=Message 
| table severity CallingMethod ErrNumber Message 

Any help appreciated.

Thanks

Tags (2)
0 Karma

niketn
Legend

@adibrr16, Please try the following run anywhere search based on your sample data. Instead of first two pipes i.e. | makeresults and | eval _raw... you can use your base search i.e. source="otc" severity="error"

| makeresults
| eval _raw=" {  
    \"id\":\"eab50eea-4b3c-4ca1-9c59-eb66500b57ea\",
    \"severity\":\"Error\",
    \"data\":{  
       \"CallingMethod\":\"UpdResponse\",
       \"ClientRequestId\":\"8fb58962-88df-4fa4-b787-163c3bca92b0\",
       \"SourceTransactionId\":\"9344949-ABS\",
       \"OrderType\":\"Domestic\",
       \"Errors\":[  
          {  
             \"ErrNumber\":14076,
             \"Message\":\"SE 2 already exists in OTC.\"
          },
          {  
             \"ErrNumber\":14076,
             \"Message\":\"SE 3 already exists in OTC.\"
          }
       ],
       \"Level\":\"Error\",
       \"TimeStamp\":\"4/19/2018 1:07:15 PM\"
    }
 }"
| spath
| rename "data.*" as "*"
| rename "Errors{}.*" as "*"
| eval ErrorData=mvzip(ErrNumber,Message)
| mvexpand ErrorData
| makemv ErrorData delim=","
| eval ErrNumber=mvindex(ErrorData,0),Message=mvindex(ErrorData,1)
| table id severity CallingMethod SourceTransactionId ErrNumber Message
____________________________________________
| makeresults | eval message= "Happy Splunking!!!"
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!

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 ...

Modernize your Splunk Apps – Introducing Python 3.13 in Splunk

We are excited to announce that the upcoming releases of Splunk Enterprise 10.2.x and Splunk Cloud Platform ...

Step into “Hunt the Insider: An Splunk ES Premier Mystery” to catch a cybercriminal ...

After a whole week of being on call, you fell asleep on your keyboard, and you hit a sequence of buttons that ...