Getting Data In

Adding and sorting key, value pairs in JSON array

evan_roggenkamp
Path Finder

This is the way my data looks:

{  
   "NODE-A":{  
      "DATA":{  
         "SNR_DATA":{  
            "Cable3/0/3-upstream2":38.1,
            "Cable3/0/3-upstream0":38.3
         },
         "MODEM_DATA":{  
            "Cable3/0/3-upstream2":14,
            "Cable3/0/3-upstream0":32
         }
      }
   }
}

I am trying to figure out how to add the values of each Cable interface under "MODEM_DATA" and present it in a table so that it can be graphed.

The farthest I have been able to get is to use spath like so:

| spath path=DATA.MODEM_DATA output=test | table test

This does not exactly break apart the key, value pairs so they can be manipulated. How to do this?

0 Karma

woodcock
Esteemed Legend

This is a general approach to demonstrate:

 | makeresults count=3
 | streamstats count AS serial
 | eval ExtendedProperties.Name="DisplayName IsPublic Mail"
 | makemv ExtendedProperties.Name
 | eval ExtendedProperties.Value=case(
    (serial=1), "Test Group::False::testgroup@microsoft.com",
    (serial=2), "Group1::True::group1@microsoft.com",
    (serial=3), "Group2::True::group2@microsoft.com")
 | makemv delim="::" ExtendedProperties.Value
 | fields - _time

 | rename COMMENT AS "Everything above generates contrived example data; everytinng below is the general solution"

 | eval KVP=mvzip('ExtendedProperties.Name', 'ExtendedProperties.Value', "=")
 | table KVP serial
 | mvexpand KVP
 | rex field=KVP "^(?<KVP_key>[^=]+)=(?<KVP_value>[^=]+)$"
 | eval {KVP_key}=KVP_value
 | fields - KVP* 
 | stats values(*) AS * BY serial
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 ...