Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
json-stats-tool
Advanced tools
This program is useful for getting simple statistics from JSON formatted files.
npm install json-stats-tool
Given this sample input file:
{"name": "john", "age": 10, "occupation": "student"}
{"name": "bob", "age": 10, "occupation": "student"}
{"name": "lucy", "age": 16, "occupation": "student"}
{"name": "linus", "age": 18, "occupation": "student"}
{"name": "charlie", "age": 18, "occupation": "student"}
{"name": "larry", "age": 50, "occupation": "doctor"}
{"name": "steve", "age": 50, "occupation": "doctor"}
{"name": "edna", "age": 45, "occupation": "programmer"}
{"name": "marcy", "age": 33, "occupation": "programmer"}
{"name": "darcy", "age": 30, "occupation": "programmer"}
We can get the average age of people by occupation:
$ ./jsonstats.js -o average -m age -d occupation < sample.json
OCCUPATION METRIC AVERAGE
student age 14
doctor age 50
programmer age 36
Or the sum of their ages:
$ ./jsonstats.js -o sum -m age -d occupation < sample.json
OCCUPATION METRIC SUM
student age 72
doctor age 100
programmer age 108
Or the count of people who are at the same age:
$ ./jsonstats.js -o count -m age < sample.json
METRIC COUNT
10 2
16 1
18 2
30 1
33 1
45 1
50 2
This works for nested objects too.
For example, say we're looking at a log file from a web server. Maybe we want to know which HTTP routes are sending back certain HTTP return codes.
If we have a JSON structure that looks something like this:
{ "route": <route_name>, "res": { "statusCode": <statusCode>, "headers": <headers> } }
We could easily find the count of status codes returned by each route:
$ grep '_audit' < muskie.log | ./jsonstats.js -m res.statusCode -d route -o count
ROUTE METRIC COUNT
headrootdir 200 3
getrootdir 200 2
unknown 404 7
headstorage 200 2
putobject 204 2
getstorage 200 2
Or if you wanted to see where the most requests are coming from you can pipe the output from this tool into other things:
$ grep 'audit' < webserver.log | ./jsonstats.js -m remoteAddress -o count -H | sort -n -k 2 | tail -n 5
172.29.1.101 1644
172.27.1.64 2201
172.29.1.103 3309
172.29.2.104 3765
172.29.1.235 30724
json-stats also supports streaming operation where the results are calculated
and printed every second. The examples above would also work with the input
being tail -f
instead of a redirected file.
MIT
FAQs
gather statistics from JSON input streams
The npm package json-stats-tool receives a total of 1 weekly downloads. As such, json-stats-tool popularity was classified as not popular.
We found that json-stats-tool demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.