Key Facts
- Category
- Data Processing
- Input Types
- textarea, select, text
- Output Type
- text
- Sample Coverage
- 4
- API Ready
- Yes
Overview
Count By is a high-performance utility that aggregates items within a JSON collection based on a specific key or property. Powered by the lodash _.countBy method, it allows you to quickly summarize data distributions and frequency counts without writing custom scripts.
When to Use
- •When you need to calculate the frequency of specific categories within a large JSON dataset.
- •When you want to group items by a shared property to understand data composition.
- •When you need a quick summary of object counts based on nested paths or identity values.
How It Works
- •Paste your JSON array or object into the collection input field.
- •Select the 'Iteratee Type' to determine if you are counting by identity or a specific property path.
- •Enter the property name or path if you chose the property-based counting method.
- •Execute the tool to receive a JSON object mapping each unique key to its total occurrence count.
Use Cases
Examples
1. Counting Product Categories
E-commerce Analyst- Background
- An analyst has a list of products and needs to know how many items are in each category.
- Problem
- Manually counting hundreds of items is prone to error.
- How to Use
- Input the product array and set the iteratee to 'category'.
- Example Config
-
Collection: [{"id":1,"category":"electronics"},{"id":2,"category":"books"},{"id":3,"category":"electronics"}], Iteratee Type: Property/Path, Iteratee: category - Outcome
- {"electronics": 2, "books": 1}
2. Summarizing HTTP Status Codes
Backend Developer- Background
- A developer is reviewing server logs to identify the distribution of response codes.
- Problem
- Need to quickly see how many 200, 404, and 500 errors occurred.
- How to Use
- Paste the log array and count by the 'status' property.
- Example Config
-
Collection: [{"status":200},{"status":200},{"status":404}], Iteratee Type: Property/Path, Iteratee: status - Outcome
- {"200": 2, "404": 1}
Try with Samples
jsonRelated Hubs
FAQ
What input formats does Count By support?
The tool accepts standard JSON arrays or JSON objects as input.
What is the difference between Identity and Property/Path?
Identity counts the occurrences of the values themselves, while Property/Path counts occurrences based on a specific key found within the objects.
Can I count by nested properties?
Yes, by selecting Property/Path, you can provide a dot-notation path to access nested values within your objects.
Is this tool based on a specific library?
Yes, this tool utilizes the industry-standard lodash _.countBy function for reliable and consistent data processing.
What is the output format?
The output is a JSON object where keys represent the unique values found and the values represent the count of those items.