Getting Data In

Json files Fields counting

abhayneilam
Contributor

Hi,
how to find the total number of fields in each event in json file in splunk
thanks in advance !!

Tags (2)
0 Karma
1 Solution

martin_mueller
SplunkTrust
SplunkTrust

You can count the number of fields in any given Splunk event like this:

your search yielding that event | fieldsummary| stats count

See http://docs.splunk.com/Documentation/Splunk/6.0.2/SearchReference/Fieldsummary for reference.

View solution in original post

0 Karma

martin_mueller
SplunkTrust
SplunkTrust

You can count the number of fields in any given Splunk event like this:

your search yielding that event | fieldsummary| stats count

See http://docs.splunk.com/Documentation/Splunk/6.0.2/SearchReference/Fieldsummary for reference.

0 Karma

abhayneilam
Contributor

Thanks its working !! I have all event with 31 fields so I cant find which event has more or less fields. BTW it is a good one , Appreciated , I am liking it !!

Thanks a lot !!

0 Karma

abhayneilam
Contributor

I have splunk 6, lemme work on that, will get back to you soon !!

0 Karma

martin_mueller
SplunkTrust
SplunkTrust

In case your last sentence meant you were looking for a field calculated for each event, you can do this:

your base search | eval fieldcount = -18 | foreach * [eval fieldcount = fieldcount + 1]

This will deduct itself and the 17 fields listed above from the total count and requires Splunk 6 to work.

0 Karma

martin_mueller
SplunkTrust
SplunkTrust

Those seventeen extra fields probably are these:

date_hour
date_mday
date_minute
date_month
date_second
date_wday
date_year
date_zone
host
index
linecount
punct
source
sourcetype
splunk_server
timeendpos
timestartpos

They're added to each event by default. You could either remove them from your search pipeline using the fields command, or just subtract 17 from your result.

0 Karma

abhayneilam
Contributor

I checked that, I have total of 31 fields in my Json File in each event, but after giving this it is coming 48 count , it is also picking up some extra fields from "interesting fields" which is not the part of the JSON file.
The output is coming as 48 but I need "Total Number of Fields per events "

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!

[Puzzles] Solve, Learn, Repeat: Matching cron expressions

This puzzle (first published here) is based on matching timestamps to cron expressions.All the timestamps ...

Why Splunk Customers Should Attend Cisco Live 2026 Las Vegas

Why Splunk Customers Should Attend Cisco Live 2026 Las Vegas     Cisco Live 2026 is almost here, and this ...

Data Management Digest – May 2026

Welcome to the May 2026 edition of Data Management Digest!   As your trusted partner in data innovation, the ...