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
Get Updates on the Splunk Community!

.conf25 Registration is OPEN!

Ready. Set. Splunk! Your favorite Splunk user event is back and better than ever. Get ready for more technical ...

Detecting Cross-Channel Fraud with Splunk

This article is the final installment in our three-part series exploring fraud detection techniques using ...

Splunk at Cisco Live 2025: Learning, Innovation, and a Little Bit of Mr. Brightside

Pack your bags (and maybe your dancing shoes)—Cisco Live is heading to San Diego, June 8–12, 2025, and Splunk ...