Getting Data In

Extracting values from a json log file

Splunkster45
Communicator

I have log file that looks like the following:

what's the best way to extract each value here. I want to evetually download this as a csv file. I'm okay with the dictionary/json for message still being a dictionary/json.

{"source_host":"a.com","method":"new","level":"INFO","message":"value = {\"sessionId\" :\"1\",\"number\":\"2\"}"}     

I tried using | spath output=_raw path=source_host, but and that worked, but I can't get multiple fields e.g.

| spath output=_raw path=source_host|method 
| spath output=_raw path=source_host,method
| spath output=_raw path=*

Any thoughts?

Tags (2)
0 Karma

somesoni2
Revered Legend

Just use the spath command (no other parameter) to extract all fields, as long as your raw data is in pure json format. See this runanywhere sample based off your sample data (additional backslashes are added to inline data generation)

| gentimes start=-1 | eval _raw="{\"source_host\":\"a.com\",\"method\":\"new\",\"level\":\"INFO\",\"message\":\"value = {\\\"sessionId\\\" :\\\"1\\\",\\\"number\\\":\\\"2\\\"}\"}" | table _raw 
| spath
0 Karma

sudosplunk
Motivator

Give this a try |spath output=_raw | table *

If you want to extract multiple values, have a look here.

0 Karma
Get Updates on the Splunk Community!

Enterprise Security Content Update (ESCU) | New Releases

In December, the Splunk Threat Research Team had 1 release of new security content via the Enterprise Security ...

Why am I not seeing the finding in Splunk Enterprise Security Analyst Queue?

(This is the first of a series of 2 blogs). Splunk Enterprise Security is a fantastic tool that offers robust ...

Index This | What are the 12 Days of Splunk-mas?

December 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...