# JSON array group count

`json-array-group-count` · version 1.0.0 · JSON & JSONL · free, no key needed

Group an array of JSON objects by exact keys and return the count.

**Use when you need to: json array group count · count json array by keys · frequency map json array.**

## Supported

- json array group count
- count json array by keys
- frequency map json array

## Not supported

- group by expression
- other aggregations

## Behavior

- Groups objects into an array of records. Each record has the join keys and a "count" key representing the number of matches.
- Output array is ordered by the first appearance of each key tuple.
- Missing or null keys are grouped together and treated as the string 'undefined' or 'null'.

## Input

- `array` (array of object, required): max items 10000
- `keys` (array of string, required): min items 1; max items 32; each min length 1
- `count_name` (string, optional): min length 1; max length 64; default `"count"`

## Output

- `result` (array of object, required)
- `groups_count` (integer, required)

## Limits

- max array items: 10000
- max output items: 10000
- max keys: 32

## Example

Request input:

```json
{
  "array": [
    {
      "id": 1,
      "v": "A"
    },
    {
      "id": 2,
      "v": "B"
    },
    {
      "id": 1,
      "v": "C"
    }
  ],
  "keys": [
    "id"
  ]
}
```

Response:

```json
{
  "result": {
    "result": [
      {
        "id": 1,
        "count": 2
      },
      {
        "id": 2,
        "count": 1
      }
    ],
    "groups_count": 2
  }
}
```

## How to call it

### MCP

Connect `https://computefirst.net/mcp` ([setup](/docs#connect)), then call `execute` with:

```json
{
  "id": "json-array-group-count",
  "version": "1.0.0",
  "input": {
    "array": [
      {
        "id": 1,
        "v": "A"
      },
      {
        "id": 2,
        "v": "B"
      },
      {
        "id": 1,
        "v": "C"
      }
    ],
    "keys": [
      "id"
    ]
  }
}
```

### HTTP (no key)

```sh
curl -X POST https://computefirst.net/v1/tools/json-array-group-count/versions/1.0.0/execute \
  -H "Content-Type: application/json" \
  -d '{"array":[{"id":1,"v":"A"},{"id":2,"v":"B"},{"id":1,"v":"C"}],"keys":["id"]}'
```

The machine-readable contract is at [/v1/tools/json-array-group-count/versions/1.0.0](/v1/tools/json-array-group-count/versions/1.0.0).

### CLI

```sh
node cli.mjs run json-array-group-count 1.0.0 --input input.json --base-url https://computefirst.net
```

Get the client at [/clients/cli/](/clients/cli/).

## Related tools

- [JSON array group by](/tools/json-array-group-by): Group an array of JSON objects by exact keys.
- [JSON array anti join](/tools/json-array-anti-join): Anti join two JSON arrays of objects on exact keys.
- [JSON array index by](/tools/json-array-index-by): Convert an array of objects into a single object indexed by a specific key.
- [JSON array sort objects](/tools/json-array-sort-objects): Stably sort an array of objects by explicit string keys using UTF-16 lexicographic order.
- [JSON array count](/tools/json-array-count): Count structural occurrences in a JSON array in first-seen order.
- [JSON array distinct by](/tools/json-array-distinct-by): Deduplicate a JSON array of objects based on specific keys.
