# Count By

Count items by a derived key using lodash _.countBy

> Canonical page: https://elysiatools.com/en/tools/count-by

- **Category:** Data Processing

- **Keywords:** count, group, lodash, collection, object

## Overview

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}`

## Inputs

- **Collection** (textarea): Enter a JSON array or object
- **Iteratee Type** (select)
- **Iteratee** (text): Property name or path when using property iteratee

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

## Frequently asked questions

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

## Related tools

- [Find Key](https://elysiatools.com/en/tools/find-key): Find the first matching key using lodash _.findKey
- [Get Path](https://elysiatools.com/en/tools/get-path): Get a value at a path using lodash _.get
- [Group By](https://elysiatools.com/en/tools/group-by): Group items by a derived key using lodash _.groupBy
- [Invert By](https://elysiatools.com/en/tools/invert-by): Invert keys grouped by values using lodash _.invertBy
- [Remove By Predicate](https://elysiatools.com/en/tools/remove-by-predicate): Remove items that match a predicate using lodash _.remove
- [Take Items](https://elysiatools.com/en/tools/take-items): Take the first N items using lodash _.take
- [Take While](https://elysiatools.com/en/tools/take-while): Take items while a predicate matches using lodash _.takeWhile
- [Zip Arrays](https://elysiatools.com/en/tools/zip-arrays): Combine arrays by index using lodash _.zip

## Samples

- [Grafana Advanced Application Samples](https://elysiatools.com/en/samples/grafana-samples): Comprehensive Grafana samples covering advanced dashboard design, alerting configurations, data source integrations, and plugin development
- [QR Code Samples](https://elysiatools.com/en/samples/qrcode-samples): Sample QR code images for testing QR code reading and generation tools
- [Postman Collections - API Testing](https://elysiatools.com/en/samples/postman-collections): Comprehensive Postman collection examples including API testing, automation scripts, environment variables, mock servers, and advanced testing patterns for REST APIs
- [D3.js Data Visualization Samples](https://elysiatools.com/en/samples/d3js-data-visualization): Comprehensive D3.js data visualization examples including charts, maps, animations, and interactive visualizations

## Related content

- [JSON Interchange and Format Translation Tools](https://elysiatools.com/en/hubs/json-convert): Compare JSON conversion tools for CSV, YAML, TOML, GraphQL, XML, Markdown, Excel, BSON, EDN, and related structured formats in one hub.
- [JSON Inspection, Diff, and Transformation Tools](https://elysiatools.com/en/hubs/json-utility): Compare JSON formatting, diffing, path inspection, schema validation, merging, transformation, and export tools in one hub for API and data workflows.
- [JSON Schema, Mock Data, and API Fixture Generators](https://elysiatools.com/en/hubs/json-generate): Curated tools for JSON schema generation, mock payload building, and API fixture preparation in one hub.
- [JSON Formatting, Diff, and Normalization Tools](https://elysiatools.com/en/hubs/json-format): Compare JSON formatting, diffing, log review, config comparison, and data-normalization tools in one hub for readable and reviewable JSON workflows.
