Splunk Search

How to use value of a one field as field name?

computernachi
New Member

Hi,
I'm a Splunk beginner here. I'm not even sure if I'm using the right terms. Kindly bear with me.
My input is a JSON file, where I have a Key 'key1' holding Value 'value1', 'key2'='value2', etc.,.
In Splunk, I see "key1" as the column name and the field value as "value1" and so on.

Now, my table already has another column with the name value1". I want to extract the column "value1" from the table.
In C/C++ terms, using value of "key1" as the index, i.e.: result = *key1;

I seem to be able to do this with something like:

| makeresults
| eval key1="value1" 
| eval value1="my_string1", value2="mystring2"
| foreach * 
       [ eval result=if("<<FIELD>>"==key1,<<FIELD>>,result)]
|  table  key1, result

Output:

key1     |    result
value1 |    "mystring1" 

But, I'm sure there should be a simpler way to do the same. All I want to do is:
result = valueof(key1's value)

Also, how would I go about doing the same if my Key1 has multiple values, where each one is a separate field?
Any ideas? Thanks!

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Community Content Calendar, September edition

Welcome to another insightful post from our Community Content Calendar! We're thrilled to continue bringing ...

Splunkbase Unveils New App Listing Management Public Preview

Splunkbase Unveils New App Listing Management Public PreviewWe're thrilled to announce the public preview of ...

Leveraging Automated Threat Analysis Across the Splunk Ecosystem

Are you leveraging automation to its fullest potential in your threat detection strategy?Our upcoming Security ...