Getting Data In

How do I extract fields from a JSON map while keeping the relationship?

atjohnso
New Member

Hi,

My stakeholders would like view events in the following JSON map log format, together in one record parsed out into separate fields:

  "cookie": [{
    "a": 1,
    "b": 1,
    "c": 1
  }, {
    "a": 2,
    "b": 2,
    "c": 2
  }, {
    "a": 3,
    "b": 3,
    "c": 3
  }]
} 

Desired report in Splunk :

a | b| c (header)
1 1 1
2 2 2
3 3 3

Is there a way to support this in Splunk?

If there is not an easy way, we can change the log structure. We wish to keep the information in JSON format, however (structuring log as a long string and regexing is not an option).

Thank you.

Tags (2)
0 Karma
1 Solution

kamlesh_vaghela
SplunkTrust
SplunkTrust

Can you please try below search?

YOUR_SEARCH
| rename cookie{}.* as * 
| eval temp = mvzip(mvzip(c,b),c) 
| stats count by _time temp 
| eval a=mvindex(split(temp,","),0),b=mvindex(split(temp,","),1),c=mvindex(split(temp,","),2) 
| table a b c

My Sample Search:

| makeresults 
| eval _raw="{ \"cookie\": [{
\"a\": 1,
\"b\": 1,
\"c\": 1
}, {
\"a\": 2,
\"b\": 2,
\"c\": 2
}, {
\"a\": 3,
\"b\": 3,
\"c\": 3
}]
}" 
| kv 
| rename cookie{}.* as * 
| eval temp = mvzip(mvzip(c,b),c) 
| stats count by _time temp 
| eval a=mvindex(split(temp,","),0),b=mvindex(split(temp,","),1),c=mvindex(split(temp,","),2) 
| table a b c

Thanks

View solution in original post

0 Karma

kamlesh_vaghela
SplunkTrust
SplunkTrust

Can you please try below search?

YOUR_SEARCH
| rename cookie{}.* as * 
| eval temp = mvzip(mvzip(c,b),c) 
| stats count by _time temp 
| eval a=mvindex(split(temp,","),0),b=mvindex(split(temp,","),1),c=mvindex(split(temp,","),2) 
| table a b c

My Sample Search:

| makeresults 
| eval _raw="{ \"cookie\": [{
\"a\": 1,
\"b\": 1,
\"c\": 1
}, {
\"a\": 2,
\"b\": 2,
\"c\": 2
}, {
\"a\": 3,
\"b\": 3,
\"c\": 3
}]
}" 
| kv 
| rename cookie{}.* as * 
| eval temp = mvzip(mvzip(c,b),c) 
| stats count by _time temp 
| eval a=mvindex(split(temp,","),0),b=mvindex(split(temp,","),1),c=mvindex(split(temp,","),2) 
| table a b c

Thanks

0 Karma

493669
Super Champion

try below in props.conf to extracts fields from JSON data.-

[<YourSourcetypeName>]
 KV_MODE=JSON
0 Karma
Get Updates on the Splunk Community!

Get Your Exclusive Splunk Certified Cybersecurity Defense Engineer at Splunk .conf24 ...

We’re excited to announce a new Splunk certification exam being released at .conf24! If you’re headed to Vegas ...

Share Your Ideas & Meet the Lantern team at .Conf! Plus All of This Month’s New ...

Splunk Lantern is Splunk’s customer success center that provides advice from Splunk experts on valuable data ...

Combine Multiline Logs into a Single Event with SOCK: a Step-by-Step Guide for ...

Combine multiline logs into a single event with SOCK - a step-by-step guide for newbies Olga Malita The ...