Categories

Count By

Count items by a derived key using lodash _.countBy

Count items by a derived key from a collection.

Highlights:

  • Uses lodash _.countBy
  • Accepts JSON arrays or objects
  • Supports identity or property/path iteratees

Example:

  • Collection: [{"type":"a"},{"type":"b"},{"type":"a"}]
  • Iteratee: type
  • Result: {"a":2,"b":1}

Enter a JSON array or object

Property name or path when using property iteratee

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

Analyzing survey results to count how many respondents selected each option.
Summarizing log files to identify the frequency of specific error codes or status types.
Categorizing inventory items to see how many products exist per category or manufacturer.

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

json

Related 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.

API Documentation

Request Endpoint

POST /en/api/tools/count-by

Request Parameters

Parameter Name Type Required Description
collection textarea Yes Enter a JSON array or object
iterateeType select No -
iteratee text No Property name or path when using property iteratee

Response Format

{
  "result": "Processed text content",
  "error": "Error message (optional)",
  "message": "Notification message (optional)",
  "metadata": {
    "key": "value"
  }
}
Text: Text

AI MCP Documentation

Add this tool to your MCP server configuration:

{
  "mcpServers": {
    "elysiatools-count-by": {
      "name": "count-by",
      "description": "Count items by a derived key using lodash _.countBy",
      "baseUrl": "https://elysiatools.com/mcp/sse?toolId=count-by",
      "command": "",
      "args": [],
      "env": {},
      "isActive": true,
      "type": "sse"
    }
  }
}

You can chain multiple tools, e.g.: `https://elysiatools.com/mcp/sse?toolId=png-to-webp,jpg-to-webp,gif-to-webp`, max 20 tools.

If you encounter any issues, please contact us at [email protected]