Splunk Search

Json Multi array extraction with changing/missing field name

psable
Explorer

Hi,
I am trying to extract the json fields where one of the fields name can change between "stringValue" or "doubleValie" and this list could be quite long , in below example I have given only two elements.

"Diagnostic": {
"Version": 2,
"diagnostic_list": [
{
"name": "FUND",
"stringValue": "One year"
},
{
"name": "RATE",
"doubleValue": 10
},
{
"name": "DATE",
"stringValue": "2016-01-01"
}

}

My json is similar to this:

rename Diagnostic{}.* as * | eval values=mvzip(name, stringValue) | mvexpand values | eval values = split(values,",") | eval name=mvindex(values,0) | eval name=mvindex(values,1) | where name=="FUND"

As you can see the problem is stringValue above could be doubleValue, so in my results I see this when i write above fields in table, the second column i.e. stringValue sometimes doesnt align with the corresponding "name" field in table.

How can I switch between stringValue and doubleValue at the run time?

Thanks,
Prashant

0 Karma
1 Solution

woodcock
Esteemed Legend

Like this:

... | rex field=_raw mode=sed "s/\"(doubleValue)\"/\"stringValue\"/g"
| rex field=_raw mode=sed "s/\"score\": {[\r\n\s]*\"scorevalue\": (\d*),[\r\n\s]*\"valueType\": \"(\w*)\"[\r\n\s]*},[\r\n\s]*\"stringValue\": \"(\w*)\",/\"stringValue\": \"\3 \1 \2\"/g"
| spath | rename diagnostic{}.* AS *
| eval nameValue=mvzip(name,stringValue, "=")
| mvexpand nameValue | fields - name stringValue

View solution in original post

0 Karma

psable
Explorer

Thank you !

0 Karma

woodcock
Esteemed Legend

Like this:

... | rex field=_raw mode=sed "s/\"(doubleValue)\"/\"stringValue\"/g"
| rex field=_raw mode=sed "s/\"score\": {[\r\n\s]*\"scorevalue\": (\d*),[\r\n\s]*\"valueType\": \"(\w*)\"[\r\n\s]*},[\r\n\s]*\"stringValue\": \"(\w*)\",/\"stringValue\": \"\3 \1 \2\"/g"
| spath | rename diagnostic{}.* AS *
| eval nameValue=mvzip(name,stringValue, "=")
| mvexpand nameValue | fields - name stringValue
0 Karma
Get Updates on the Splunk Community!

Security Professional: Sharpen Your Defenses with These .conf25 Sessions

Sooooooooooo, guess what. .conf25 is almost here, and if you're on the Security Learning Path, this is your ...

First Steps with Splunk SOAR

Our first step was to gather a list of the playbooks we wanted and to sort them by priority.  Once this list ...

How To Build a Self-Service Observability Practice with Splunk Observability Cloud

If you’ve read our previous post on self-service observability, you already know what it is and why it ...