Splunk Search

How to extract a field out of JSON, and then use to get a count

chktlm
New Member

Hi. I am trying to get a count on the first field within my logs, of the requestBody json input. Below is an example of the log:

2019-11-20 17:20:03,802 INFO  [qqq1000000-10000] web.service.logging.IncomingRequest: ip=00.00.00.000, domain=http://url:0000/webService/web/Service/, username=null, date=[20/Nov/2019:17-20-03,802 +0000], method=POST uri=/webService/web/Service?schema=1.0&form=JSON&httpError=true&cid=12345, status=200, contentLength=68, responseTime=190, userAgent=WebServiceClient<Service> 3.5, referrer=, cacheStatus=miss, cid=12345 requestBody={"createPerson":{"customerId":"55555555.customer"}}, x-accountexternalid=987654321, api=service.create, x-partner=Partner, cid=12345

How would I grab the first entry in the JSON of the requestBody element, and then make that a field, so I can get a count. From the example above, I would want to grab createPerson from the requestBody section. Make this a field so I can then grab a count of the incoming requestBody first element? There would be other fields besides just createPerson. So I just want to extract that field within the quote, and get the count for each different element that is in that position of our incoming requests.

Tags (1)
0 Karma
1 Solution

mayurr98
Super Champion

try this:

...| rex "requestBody=\{\"(?<requestBody>\w+)" | stats count by requestBody

View solution in original post

0 Karma

mayurr98
Super Champion

try this:

...| rex "requestBody=\{\"(?<requestBody>\w+)" | stats count by requestBody
0 Karma

chktlm
New Member

Thank you very much mayurr98. Worked perfectly!

0 Karma
Get Updates on the Splunk Community!

Announcing Scheduled Export GA for Dashboard Studio

We're excited to announce the general availability of Scheduled Export for Dashboard Studio. Starting in ...

Extending Observability Content to Splunk Cloud

Watch Now!   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to leverage ...

More Control Over Your Monitoring Costs with Archived Metrics GA in US-AWS!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...