# Invert Object

Invert keys and values using lodash _.invert

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

- **Category:** Data Processing

- **Keywords:** invert, object, lodash, keys, values

## Overview

Swap keys and values in an object.

**Highlights:**
- Uses lodash `_.invert`
- Values become string keys
- Later values overwrite earlier keys

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

## Inputs

- **Object** (textarea): Enter a JSON object

## When to use

- When you need to perform a reverse lookup by finding the original key associated with a specific value.
- When restructuring configuration objects to make values the primary identifiers.
- When cleaning up data mappings where you need to verify unique value assignments.

## How it works

- Paste your JSON object into the input area.
- The tool processes the object using the lodash _.invert function.
- The output displays a new object where original values become keys and original keys become values.
- Note that if multiple keys share the same value, the last key processed will overwrite previous ones in the resulting object.

## Use cases

- Mapping error codes to error messages and then inverting them to find the code from a message.
- Converting a list of user IDs mapped to usernames into a lookup table for user IDs.
- Refactoring configuration files where you need to switch between key-value and value-key access patterns.

## Frequently asked questions

### What happens if my object has duplicate values?

Since keys in a JSON object must be unique, the last key encountered for a specific value will be the one preserved in the output.

### Does this tool support nested objects?

The tool performs a shallow inversion. Nested objects will be treated as string values and may not produce the desired structure.

### What library does this tool use?

This tool utilizes the standard lodash _.invert function for consistent and predictable results.

### Are the resulting keys always strings?

Yes, in JavaScript objects, keys are converted to strings, so the inverted values will become string keys in the output.

### Is my data sent to a server?

No, the inversion process happens locally in your browser for maximum privacy and speed.

## Related tools

- [Assign In Object](https://elysiatools.com/en/tools/assign-in-object): Assign own and inherited properties using lodash _.assignIn
- [Defaults Deep](https://elysiatools.com/en/tools/defaults-deep): Apply deep default values using lodash _.defaultsDeep
- [Invert By](https://elysiatools.com/en/tools/invert-by): Invert keys grouped by values using lodash _.invertBy
- [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
- [Count By](https://elysiatools.com/en/tools/count-by): Count items by a derived key using lodash _.countBy
- [Find Key](https://elysiatools.com/en/tools/find-key): Find the first matching key using lodash _.findKey
- [For In Object](https://elysiatools.com/en/tools/for-in-object): Iterate over object properties using lodash _.forIn

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

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