Count occurances of values across objects and arrays.
No future updates are planned. Feel free to continue using it, but expect no support.
This is a package for the command-line JSON processor jq
. Install the package in your jq project/package directory with jqnpm
:
jqnpm install joelpurra/jq-key-counter
import "joelpurra/jq-key-counter" as KeyCounter;
# Create a new key counter object.
KeyCounter::create # {}
# Increment the "a" key.
| KeyCounter::increment("a") # { "a": 1 }
# Increment by an arbitrary (positive or negative) integer.
| KeyCounter::incrementBy("b"; 7) # { "a": 1, "b": 7 }
# Decrement a single key.
| KeyCounter::decrement("b") # { "a": 1, "b": 6 }
# Add two key counter objects.
| KeyCounter::add({ "a": 4, "c": 3 }) # { "a": 5, "b": 6, "c": 3 }
# Add an array of keys.
| KeyCounter::incrementByArray([ "b", "c", "d" ]) # { "a": 5, "b": 7, "c": 4, "d": 1 }
# Drop values below 3;
| KeyCounter::minimum(3) # { "a": 5, "b": 7, "c": 4 }
# Get the top 2 values, sorted by values (descending):
| KeyCounter::top(2) # { "b": 7, "a": 5 }
Copyright (c) 2014, 2015, Joel Purra https://joelpurra.com/ All rights reserved.
When using jq-key-counter, comply to the MIT license. Please see the LICENSE file for details.