Key Facts
- Category
- Data Processing
- Input Types
- textarea, text
- Output Type
- text
- Sample Coverage
- 4
- API Ready
- Yes
Overview
The Invert By tool allows you to restructure JSON objects by grouping keys based on their corresponding values. Powered by the lodash _.invertBy method, this utility simplifies data transformation by collecting keys into arrays associated with unique values or transformed property paths.
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
Examples
1. Categorizing User Roles
- Background
- A developer has a list of users and their roles and needs to generate a list of users per role for a dashboard.
- Problem
- The current data is structured as {user: role}, but the UI requires {role: [users]}.
- How to Use
- Input the user-role object and run the tool to invert the mapping.
- Example Config
-
{"Alice":"Admin", "Bob":"Editor", "Charlie":"Admin"} - Outcome
- {"Admin":["Alice","Charlie"], "Editor":["Bob"]}
2. Grouping by Nested Property
- Background
- An API response contains items with nested status information that needs to be grouped.
- Problem
- Need to group items by the 'status' property located inside a nested object.
- How to Use
- Input the object and specify 'status' in the Iteratee Path field.
- Example Config
-
{"item1":{"status":"active"}, "item2":{"status":"pending"}, "item3":{"status":"active"}} - Outcome
- {"active":["item1","item3"], "pending":["item2"]}
Try with Samples
jsonRelated Hubs
FAQ
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.