Splunk Search

Large Json Array, Spath and stats

jondukehds
Explorer

So I have a large JSON array that is now being brought in and ingested correctly, but I cannot do any stats function on it. What I'd like to do are things like this, but the below search just brings in the same value for each name.

 

 

index=storage sourcetype="netbackup:license"
| spath output=Name path=data{}.attributes.clientDetails{}.clientName
| spath output=ClientConsumptionMB path=data{}.attributes.clientDetails{}.clientConsumptionMB
| spath output=PolicyName path=data{}.attributes.clientDetails{}.policyDetails{}.policyName
| spath output=PolicyType path=data{}.attributes.clientDetails{}.policyDetails{}.policyType
|stats last(ClientConsumptionMB) by Name

 

 

 

 

So then I tried to do this.

 

 

 

index=storage sourcetype="netbackup:license"
| spath output=Name path=data{}.attributes.clientDetails{}.clientName
| spath output=ClientConsumptionMB path=data{}.attributes.clientDetails{}.clientConsumptionMB
| spath output=PolicyName path=data{}.attributes.clientDetails{}.policyDetails{}.policyName
| spath output=PolicyType path=data{}.attributes.clientDetails{}.policyDetails{}.policyType
| eval Name=upper(Name)
| eval NameCount=mvzip(Name,ClientConsumptionMB)
| mvexpand NameCount
| eval mvNameCount=split(NameCount,",")
| eval Name=mvindex(mvNameCount,0)
| eval ClientConsumptionMB=mvindex(mvNameCount,1)
| stats last(ClientConsumptionMB) by Name

 

 

 

And ran into a 300 line limit for mvexpand.

Help?

Labels (1)
0 Karma

quzen
Explorer

Doing nomv on the extracted field helped me:

| nomv Name

 After that stats by that field worked.

0 Karma

tscroggins
Influencer

@jondukehds 

Assuming this is output from the NetBackup Licensing API, we can use mock test data:

 

{
  "data": [
    {
      "type": "string",
      "id": "string",
      "attributes": {
        "masterConsumptionMB": 0,
        "clientDetails": [
          {
            "clientName": "client1",
            "clientConsumptionMB": 123,
            "policyDetails": [
              {
                "backupId": "string",
                "policyName": "string",
                "masterServer": "string",
                "policyType": "string",
                "policyConsumptionMB": 0
              }
            ]
          },
          {
            "clientName": "client2",
            "clientConsumptionMB": 456,
            "policyDetails": [
              {
                "backupId": "string",
                "policyName": "string",
                "masterServer": "string",
                "policyType": "string",
                "policyConsumptionMB": 0
              }
            ]
          }
        ]
      }
    }
  ],
  "meta": {
    "pagination": {
      "prev": 0,
      "next": 0,
      "first": 0,
      "last": 0,
      "count": 0,
      "offset": 0,
      "limit": 0
    }
  }
}

 

We have clientName values client1 and client2 with clientConsumptionMB values 123 and 456, respectively.

Putting this into a synthetic search:

| makeresults
| eval capacity="{\"data\":[{\"type\":\"string\",\"id\":\"string\",\"attributes\":{\"masterConsumptionMB\":0,\"clientDetails\":[{\"clientName\":\"client1\",\"clientConsumptionMB\":123,\"policyDetails\":[{\"backupId\":\"string\",\"policyName\":\"string\",\"masterServer\":\"string\",\"policyType\":\"string\",\"policyConsumptionMB\":0}]},{\"clientName\":\"client2\",\"clientConsumptionMB\":456,\"policyDetails\":[{\"backupId\":\"string\",\"policyName\":\"string\",\"masterServer\":\"string\",\"policyType\":\"string\",\"policyConsumptionMB\":0}]}]}}],\"meta\":{\"pagination\":{\"prev\":0,\"next\":0,\"first\":0,\"last\":0,\"count\":0,\"offset\":0,\"limit\":0}}}"
| spath input=capacity
| rename "data{}.attributes.clientDetails{}.clientName" as clientName, "data{}.attributes.clientDetails{}.clientConsumptionMB" as clientConsumptionMB
| eval consumption=mvzip(clientName, clientConsumptionMB, "|")
| fields consumption
| mvexpand consumption
| eval consumption=split(consumption, "|"), clientName=mvindex(consumption, 0), clientConsumptionMB=mvindex(consumption, 1)
| fields - consumption
| stats latest(clientConsumptionMB) as clientConsumptionMB by clientName

yields:

clientNameclientConsumptionMB
client1123
client2456

 

mvexpand has no default result limit; it's memory bound by the max_mem_usage_mb setting in the mvexpand stanza in limits.conf. If you're hitting the memory ceiling, try reducing your footprint as I've done above. If that fails, try increasing (or asking your Splunk administrator to increase) max_mem_usage_mb.

0 Karma
Get Updates on the Splunk Community!

Data Management Digest – December 2025

Welcome to the December edition of Data Management Digest! As we continue our journey of data innovation, the ...

Index This | What is broken 80% of the time by February?

December 2025 Edition   Hayyy Splunk Education Enthusiasts and the Eternally Curious!    We’re back with this ...

Unlock Faster Time-to-Value on Edge and Ingest Processor with New SPL2 Pipeline ...

Hello Splunk Community,   We're thrilled to share an exciting update that will help you manage your data more ...