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!

SOC4Kafka - New Kafka Connector Powered by OpenTelemetry

The new SOC4Kafka connector, built on OpenTelemetry, enables the collection of Kafka messages and forwards ...

Event Series: Level up your SOC: Advancing with Splunk Enterprise Security

AI has fundamentally raised the stakes for security operations, and this three-part series is your guide to ...

Announcing Modern Navigation: A New Era of Splunk User Experience

We are excited to introduce the Modern Navigation feature in the Splunk Platform, available to both cloud and ...