Splunk Search

Help extracting totalCount out of nested JSON

bhavya49
New Member
{ [-]
   detailMap: { [-]
     critical: false
     result: 0
     totalCnt: 5
     txnCountWithIgnoredIRC: 0
     warning: false
   }
   id: 60300000000
   name: EBALL
}

I'm trying to extract totalCount out of the nested Json. I'm trying the below search to extract it:

index="pas" source="agent.log" | spath output=myCount path=detailMap{}.totalCnt | table myCount

When I'm running this search, myCount column is blank.
Please let me know how to improvise this search.

0 Karma

to4kawa
Ultra Champion
| makeresults
| eval _raw = "{ 
    \"detailMap\": { 
      \"critical\": \"false\",
      \"result\": \"0\",
      \"totalCnt\": \"5\",
      \"txnCountWithIgnoredIRC\": \"0\",
      \"warning\": \"false\"
    },
    \"id\": \"60300000000\",
    \"name\": \"EBALL\"
 }"
| spath

From this results,

index="pas" source="agent.log" 
| spath output=myCount path=detailMap.totalCnt 
| table myCount

It looks like the field name is different.

0 Karma

vnravikumar
Champion

Hi

Try this

| makeresults 
| eval temp="{
  \"detailMap\": {
    \"critical\": false,
    \"result\": 0,
    \"totalCnt\": 5,
    \"txnCountWithIgnoredIRC\": 0,
    \"warning\": false
  },
  \"id\": 60300000000,
  \"name\": \"EBALL\"
        }" 
| spath input=temp output=totalCnt path=detailMap{}.totalCnt | table totalCnt
0 Karma
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...