Getting Data In

How do you select a key value based on key name?

jmount15
New Member

I have a log that looks similar to this:

`{
"name": "Joe",
"variables":[
{
"variableName":"age",
"variableValue":"30"
},
{
"variableName":"gender",
"variableValue":"male"
},
{
"variableName":"state",
"variableValue":"WA"
}]

}`

How do I go about selecting for example the gender or age in this log?

Tags (2)
0 Karma

chrisyounger
SplunkTrust
SplunkTrust

You can do this:

YOUR_SEARCH | rex "\"variableName\"\s*:\s*\"age\"\s*,\s*\"[^\"]+\"\s*:\s*\"(?<age>[^"]*)\""

to get the age. Or you can use this sort of field extraction to extract all values properly:

props.conf

[my_sourcetype]
REPORT-my_json_pairs = my_json_pairs

transforms.conf

[my_json_pairs]
REGEX = \"variableName\"\s*:\s*\"(?<_KEY_1>[^"]*)\"\s*,\s*\"[^\"]+\"\s*:\s*\"(?<_VAL_1>[^"]*)\"

All the best

0 Karma
Get Updates on the Splunk Community!

Automatic Discovery Part 1: What is Automatic Discovery in Splunk Observability Cloud ...

If you’ve ever deployed a new database cluster, spun up a caching layer, or added a load balancer, you know it ...

Real-Time Fraud Detection: How Splunk Dashboards Protect Financial Institutions

Financial fraud isn't slowing down. If anything, it's getting more sophisticated. Account takeovers, credit ...

Splunk + ThousandEyes: Correlate frontend, app, and network data to troubleshoot ...

 Are you tired of troubleshooting delays caused by siloed frontend, application, and network data? We've got a ...