Splunk Search

Extracting Key Value Pairs from a JSON object and convert them to fields

thenino
Loves-to-Learn Lots

Hello Splunk Community,

We have two types of logs being forwarded to splunk a simple .log file and json logs that are being forwarded to splunk.  

I am only interested in one of the objects which has key-value pairs.  In this example I am only interested in the log object.  

JSON LOG

 

{ [-]
   kubernetes: { [+]
   }
   log: 2020-06-24T13:23:12.8735410Z CI=4fomit248-2e46-4omit9-8019-838cdac1a4a4 L=INFO This is some log message here HRM=GET HRU=http://00.00.000.00:80/bar/v1/foo IP=::ffff:00.00.000.000 AV=? HSC=200 ET=1

   stream: stdout
   time: 2020-06-24T13:23:12.873853339Z
}

 

In the log object I want the fields to be extracted as followed:

KeyValue
CI4fomit248-2e46-4omit9-8019-838cdac1a4a4
LINFO
IP::ffff:00.00.000.000
<THIS WOULD BE THE LOG MESSAGE NOT A KEY>This is some log message here

 

I understand how to parse fields from the spath output using regex. However I would prefer this is is parsed at index time.

Our other set of logs are exactly what is in the log object they are not in JSON format and splunk picks up the fields just fine.

Log from .log file

 

2020-06-24 06:41:31.195 ST=C5D17Domitted72738B0D136DA9 CI=b1d0b050-omitted-46d2-omitted-80a61dfadf7d L=INFO  Some log message here HRM=GET SN=FOO MN=Get HRU=http://foo.omit/bar/v2/foobar IP=00.00.000.000 ET=31 HSC=200 FOWCF=4

 

CurrentLogs.png

Is it possible to extract the log object at index time and turn it into its own log where the key value pairs are extracted as fields?

I also read this blog post is this the best approach?
Eureka! Extracting key-value pairs from JSON fields 

Labels (1)
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!

Why Splunk Customers Should Attend Cisco Live 2026 Las Vegas

Why Splunk Customers Should Attend Cisco Live 2026 Las Vegas     Cisco Live 2026 is almost here, and this ...

What Is the Name of the USB Key Inserted by Bob Smith? (BOTS Hint, Not the Answer)

Hello Splunkers,   So you searched, “what is the name of the usb key inserted by bob smith?”  Not gonna lie… ...

Automating Threat Operations and Threat Hunting with Recorded Future

    Automating Threat Operations and Threat Hunting with Recorded Future June 29, 2026 | Register   Is your ...