JSON Array Grouper

Groups a JSON array of objects into an object of arrays, bucketed by the string value of a chosen key on each item, similar to a SQL GROUP BY over a JSON array. A free online tool from Staaarter, right in your browser.

Runs locallyUpdated 2026-07-24

Overview

Introduction

A flat JSON array of records, orders grouped by customer, log entries grouped by level, users grouped by role, is often easier to work with once it's bucketed by some shared field. Writing that grouping logic by hand is a common but repetitive task.

This tool does that grouping directly in the browser: give it an array and a key, and it returns an object whose keys are the distinct values of that field.

What Is JSON Array Grouper?

A grouping tool that takes a JSON array of objects and a group-by key name, and returns a JSON object where each key is a distinct value of that field and each value is the array of matching items.

It's the JSON equivalent of a SQL GROUP BY without an aggregate function: rather than collapsing each group to a single summary row, every original item is kept, just reorganized into its bucket.

How JSON Array Grouper Works

For each item in the array, the tool reads item[groupByKey], converts it to a string, and appends the original item to that string's bucket in an accumulator object, creating the bucket on first use.

Once every item has been processed, the accumulator (an object mapping each distinct key value to its array of items) is serialized as the JSON output.

When To Use JSON Array Grouper

Use it when you have a flat array of records and want to see them organized by a shared field, orders by status, users by role, events by type, without writing a reduce() by hand.

It's also useful as a quick way to spot which distinct values a field actually takes across a data set, since each resulting top-level key is one of those distinct values.

Often used alongside JSON Filter, JSONPath Tester and JSON Analyzer.

Features

Advantages

  • Handles any scalar-valued key, string, number, or boolean, converting it to a group key automatically.
  • Preserves each item's original position within its group.
  • Groups items with a missing key under a clearly labeled "undefined" bucket instead of erroring or dropping them.

Limitations

  • Only groups by a single top-level key; it doesn't support nested paths like address.city or computed grouping expressions.
  • There's no aggregation step, the output is grouped raw items, not counts, sums, or other summaries per group.

Examples

Grouping orders by status

Input

[{"id":1,"status":"paid"},{"id":2,"status":"pending"},{"id":3,"status":"paid"}]

Output

{
  "paid": [
    { "id": 1, "status": "paid" },
    { "id": 3, "status": "paid" }
  ],
  "pending": [
    { "id": 2, "status": "pending" }
  ]
}

Items are bucketed under a key equal to their own "status" value, in their original relative order.

Non-array input

Invalid input

{"id": 1}

Parser error

Top-level JSON value must be an array to group.

Grouping requires a top-level array of items; a single object has no items to bucket.

Corrected version

[{"id": 1}]

Best Practices & Notes

Best Practices

  • Double-check the group-by key's exact spelling and casing; a typo produces a single "undefined" bucket rather than an error, which can look like a successful (but wrong) result.
  • For nested grouping keys, flatten the array's objects first with JSON Object Flattener so a nested field becomes a top-level dotted key you can group by.
  • If you need counts per group rather than the full items, this tool's output is the right input to a short script that maps each group to its length.

Developer Notes

The group key is computed with String(item[groupByKey]) rather than a type-preserving comparison, which is intentional: JSON object keys are always strings by specification, so any grouping tool that outputs a JSON object has to make this conversion somewhere, and doing it explicitly up front avoids surprises like the numeric group 1 and the string group "1" silently colliding or not colliding depending on where the conversion happened.

JSON Array Grouper Use Cases

  • Grouping orders or transactions by status
  • Bucketing log entries by severity level
  • Organizing a flat list of users by role or department

Common Mistakes

  • Misspelling the group-by key and not noticing everything landed in a single "undefined" bucket.
  • Expecting nested-path grouping (like "address.city") to work directly; flatten the array first if you need that.

Tips

  • Pair this with Filter JSON if you only want to group a subset of the array to begin with.
  • Use JSON Analyzer first if you're not sure what fields are available to group by.

References

Frequently Asked Questions