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
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Event Series May & June: From Network Visibility to Service Intelligence

Unifying the Network: Moving from Alert Noise to Service Intelligence with Splunk ITSI In today’s hybrid ...

Global Splunk User Group Events: May + June 2026

Your Splunk Community Awaits: Discover Upcoming User Group Events Worldwide    Staying ahead in the fast-paced ...

Why Splunk Customers Should Attend Cisco Live 2026 Las Vegas

Why Splunk Customers Should Attend Cisco Live 2026 Las Vegas     Cisco Live 2026 is almost here, and this ...