Splunk Search

How to query and extract value fra Json array

thoj
New Member

Having the json data/array below, how do I create a new (single value) field with only the TargetVersion that has IsPreferred = true

"TargetVersions": [
{
"IsPreferred": false
...
},
{
"IsPreferred": true
...
]

Tags (1)
0 Karma

renjith_nair
Legend

@thoj,

Assuming you have some other value for e.g. version inside your json structure, you could use spath to extract from json array.

Something similar to below (added version as a value),

|makeresults|eval json="{\"TargetVersions\": [
{
\"IsPreferred\": false,
\"Version\" : \"1.0\"
},
{
\"IsPreferred\": true,
\"Version\" : \"2.0\"
]
}"|spath input=json|fields - json,_time
|rename "TargetVersions{}.IsPreferred" as IsPreferred,"TargetVersions{}.Version" as Version
|eval zipped=mvzip(IsPreferred,Version)|fields zipped|mvexpand zipped|makemv delim="," zipped
|eval IsPreferred=mvindex(zipped,0),Version=mvindex(zipped,1)|fields - zipped|where IsPreferred="true"
---
What goes around comes around. If it helps, hit it with Karma 🙂
0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.
Get Updates on the Splunk Community!

Observe and Secure All Apps with Splunk

 Join Us for Our Next Tech Talk: Observe and Secure All Apps with SplunkAs organizations continue to innovate ...

What's New in Splunk Observability - August 2025

What's New We are excited to announce the latest enhancements to Splunk Observability Cloud as well as what is ...

Introduction to Splunk AI

How are you using AI in Splunk? Whether you see AI as a threat or opportunity, AI is here to stay. Lucky for ...