# How to Use jq `sort_by`, `group_by`, and `unique_by` with Custom Comparators

> Learn to use jq sort_by, group_by, and unique_by with custom comparators. Leverage jq expressions for powerful sorting, grouping, and deduplication in your JSON data.

- Repository: [jqlang/jq](https://github.com/jqlang/jq)
- Tags: how-to-guide
- Published: 2026-04-11

---

**jq implements `sort_by`, `group_by`, and `unique_by` as thin wrappers around optimized C functions that accept arbitrary jq expressions as comparators, converting them into parallel key arrays for sorting, grouping, or deduplication.**

The `jqlang/jq` repository provides powerful collection manipulation utilities that allow you to use any valid jq filter as a comparator. These functions reside in the standard library and delegate heavy lifting to optimized C implementations, enabling complex data transformations with concise syntax.

## How Custom Comparators Work in jq