# Invert By

Invert keys grouped by values using lodash _.invertBy

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

- **Category:** Data Processing

- **Keywords:** invertBy, object, lodash, group, keys

## Overview

Group keys by their values or by a transformed value.

**Highlights:**
- Uses lodash `_.invertBy`
- Groups keys into arrays
- Optional property path iteratee

**Example:**
- Object: `{"a":"x","b":"x","c":"y"}`
- Result: `{"x":["a","b"],"y":["c"]}`

## Inputs

- **Object** (textarea): Enter a JSON object
- **Iteratee Path** (text): Optional property path for value transform

## When to use

- When you need to categorize a flat list of items by a specific shared attribute.
- When you want to identify all keys that share the same value within a large JSON dataset.
- When you need to group nested object properties based on a specific path for easier data analysis.

## How it works

- Paste your source JSON object into the input area.
- Optionally, provide an 'Iteratee Path' if you want to group by a specific property within the values.
- Click the process button to generate a new object where values become keys and original keys are grouped into arrays.
- Copy or download the resulting JSON output for use in your application.

## Use cases

- Aggregating user IDs by their assigned roles or status codes.
- Organizing configuration settings by their environment or type.
- Mapping database records to specific categories for faster lookup.

## Frequently asked questions

### What does the Invert By tool do?

It transforms an object by swapping its keys and values, grouping all original keys that share the same value into an array.

### What is the 'Iteratee Path' used for?

It allows you to group keys based on a specific property path within the values, rather than the values themselves.

### Is this tool based on a specific library?

Yes, it utilizes the lodash _.invertBy function to ensure consistent and reliable data processing.

### What happens if multiple keys have the same value?

The tool will group all those keys into a single array under that value in the resulting object.

### Can I process nested objects?

Yes, by using the Iteratee Path, you can target specific nested properties to determine how the keys should be grouped.

## Related tools

- [Count By](https://elysiatools.com/en/tools/count-by): Count items by a derived key using lodash _.countBy
- [Defaults Deep](https://elysiatools.com/en/tools/defaults-deep): Apply deep default values using lodash _.defaultsDeep
- [Group By](https://elysiatools.com/en/tools/group-by): Group items by a derived key using lodash _.groupBy
- [Invert Object](https://elysiatools.com/en/tools/invert-object): Invert keys and values using lodash _.invert
- [Keys In List](https://elysiatools.com/en/tools/keys-in-list): List own and inherited keys using lodash _.keysIn
- [Keys List](https://elysiatools.com/en/tools/keys-list): List own enumerable keys using lodash _.keys
- [Unzip Arrays](https://elysiatools.com/en/tools/unzip-arrays): Split grouped arrays using lodash _.unzip
- [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
- [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
- [Rome JavaScript Toolchain Samples](https://elysiatools.com/en/samples/rome): Rome JavaScript toolchain examples including configuration, linting, formatting, bundling, and project management
