Splunk Search

Find first matching node of json

nainil0683
Engager

Hi,

      Based on the following json document, I want to find the value of "Geography" where City is input.

Here is the json:

 

 

 

{
    "Company" : "Microsoft",
    "Cloud" : "Azure",
    "DataCenters" : [
        {
            "Geography" : "USA",
            "Region" : "East",
            "City": "New York"
        },
        {
            "Geography" : "India",
            "Region" : "West",
            "City": "Ahmedabad"
        }, 
        {
            "Geography" : "USA",
            "Region" : "West",
            "City": "San Fransisco"
        },
        {
            "Geography" : "South Africa",
            "Region" : "West",
            "City": "Capetown"
        }
    ]
}

 

 

 

Can somebody please help me fetch this information. Thanks.

0 Karma

yuanliu
SplunkTrust
SplunkTrust

Assuming you already have a token $City_tok$ from the input, mvexpand is the most traditional way to do it

| spath path=DataCenters{}
| mvexpand DataCenters{}
| spath input=DataCenters{}
| whree City == "$City_tok$"

If mvexpand is a problem in your environment, there are other ways.

Tags (1)
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!

May 2026 Splunk Expert Sessions: Security & Observability

Level Up Your Operations: May 2026 Splunk Expert Sessions Whether you are refining your security posture or ...

Network to App: Observability Unlocked [May & June Series]

In today’s digital landscape, your environment is no longer confined to the data center. It spans complex ...

SPL2 Deep Dives, AppDynamics Integrations, SAML Made Simple and Much More on Splunk ...

Splunk Lantern is Splunk’s customer success center that provides practical guidance from Splunk experts on key ...