Categories

Sorted Unique By

Remove duplicates from a sorted array using lodash _.sortedUniqBy

Remove duplicates from a sorted array using a property path.

Highlights:

  • Uses lodash _.sortedUniqBy
  • Supports property paths (e.g. id, meta.key)
  • Returns unique values as JSON

Example:

  • Array: [{"id": 1}, {"id": 1}, {"id": 2}]
  • Path: id
  • Result: [{"id": 1}, {"id": 2}]

Enter a JSON array

Property path used to compare values

Key Facts

Category
Data Processing
Input Types
textarea, text
Output Type
text
Sample Coverage
4
API Ready
Yes

Overview

This tool removes duplicate entries from a pre-sorted array by comparing values at a specified property path, using the lodash _.sortedUniqBy function to return a unique JSON array.

When to Use

  • When you have a sorted list of objects and need to eliminate duplicates based on a specific key or nested property.
  • To clean up data from APIs, databases, or exports where duplicates might occur in sorted order without re-sorting.
  • When preparing data for further processing, analysis, or display, ensuring uniqueness while maintaining the original sort sequence.

How It Works

  • Input a JSON array that is already sorted in ascending order.
  • Specify the property path to compare for duplicates, such as 'id' or 'meta.key'.
  • The tool applies lodash's _.sortedUniqBy to remove consecutive duplicate entries based on the path.
  • Output the resulting unique array as JSON, preserving the sort order.

Use Cases

Deduplicating user records from a sorted database export based on user ID.
Cleaning up sorted log entries by unique error codes or timestamps.
Processing sorted inventory lists to remove duplicate product SKUs for accurate reporting.

Examples

1. Deduplicate User Records

Data Analyst
Background
You have a sorted JSON array of user objects exported from a CRM system, sorted by registration date.
Problem
Duplicate user entries exist with the same 'userId' field, skewing analytics.
How to Use
Paste the sorted array into the Array field and set the Property Path to 'userId'.
Outcome
A JSON array with unique user objects, ready for accurate analysis without duplicates.

2. Clean Sorted Product Inventory

Background
An e-commerce platform provides a product list sorted by SKU, but some entries are duplicated.
Problem
Duplicate SKUs need removal to ensure inventory counts are correct.
How to Use
Input the sorted product array and specify 'sku' as the property path.
Outcome
A unique product list in JSON format, maintaining sort order for inventory management.

Try with Samples

json, video

Related Hubs

FAQ

What input format is required?

A JSON array that must be sorted before use.

Can I use nested property paths?

Yes, paths like 'meta.key' are supported for comparing nested values.

What if the array is not sorted?

The tool assumes sorted input; unsorted arrays may not produce correct results.

Is the output in JSON format?

Yes, the result is a JSON array of unique objects.

Do I need to install lodash?

No, the tool uses lodash internally; you only provide the input array and path.

API Documentation

Request Endpoint

POST /en/api/tools/sorted-unique-by

Request Parameters

Parameter Name Type Required Description
array textarea Yes Enter a JSON array
path text No Property path used to compare values

Response Format

{
  "result": "Processed text content",
  "error": "Error message (optional)",
  "message": "Notification message (optional)",
  "metadata": {
    "key": "value"
  }
}
Text: Text

AI MCP Documentation

Add this tool to your MCP server configuration:

{
  "mcpServers": {
    "elysiatools-sorted-unique-by": {
      "name": "sorted-unique-by",
      "description": "Remove duplicates from a sorted array using lodash _.sortedUniqBy",
      "baseUrl": "https://elysiatools.com/mcp/sse?toolId=sorted-unique-by",
      "command": "",
      "args": [],
      "env": {},
      "isActive": true,
      "type": "sse"
    }
  }
}

You can chain multiple tools, e.g.: `https://elysiatools.com/mcp/sse?toolId=png-to-webp,jpg-to-webp,gif-to-webp`, max 20 tools.

If you encounter any issues, please contact us at [email protected]